文章
105
粉丝
69
获赞
117
访问
54.2k
注意是多组测试输入 (没注意就WA一次)
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int dp[N], w[N];
int n, m;
int main()
{
while(cin >> m >> n)
{
memset(dp, 0, sizeof dp);
for(int i = 1; i <= n; i ++)
cin >> w[i];
for(int i = 1; i <= n; i ++)
for(int j = m; j >= w[i]; j --)
dp[j] = max(dp[j], dp[j - w[i]] + w[i]);
if(dp[m] == m) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发