文章
84
粉丝
408
获赞
33
访问
872.1k
注意:有多组测试用例
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int s, n;
while (cin >> s >> n) {
int* w = new int[n];
for (int i = 0; i < n; i++)
cin >> w[i];
bool* dp = new bool[s+1];
memset(dp, 0, sizeof(dp));
dp[0] = true;
for (int i = 0; i < n; i++) {
for (int j = s; j >= w[i]; j--) {
if (dp[j-w[i]])
dp[j] = true;
}
}
if (dp[s])
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发