求助 全部WA 但是我试了好几个数都没问题
查看原帖
求助 全部WA 但是我试了好几个数都没问题
1307967
stone_thousand楼主2024/3/28 15:02
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int n, ans;
int w[110];
set<int> s;
set<int>::iterator it;
vector<int>::iterator it1;

int DP(int* w)
{
	int* dp = new int[n + 100000];
	dp[1] = 1;
	s.insert(w[0]);
	for (int i = 2; i <= n; i++)
	{
		vector<int> num = {};
		for (it = s.begin(); it != s.end(); it++)
		{
			num.push_back(abs(w[i - 1] - *it));
			num.push_back(w[i - 1] + *it);
		}
		num.push_back(w[i - 1]);
		for (it1 = num.begin(); it1 != num.end(); it1++)
		{
			s.insert(*it1);
		}
		dp[i] = s.size();
	}
	return dp[n];
}
// 
// 1 
// 1 2
// 5 3 4 6 
// 
// 1
// 1 3 // 1 2 4
// 1 3 3 //  5 7 
// 1 10000 1
// 9999 
// 10001
// 1 10000 9999 10001
// 2 9998 10002
// 10 20 // 5 15 25 35 
// 13 14 1 27
// 2 28 15 29 14 
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> w[i];
	}
	sort(w, w+n);
	ans = DP(w);
	cout << ans;
	return 0;
}
2024/3/28 15:02
加载中...