文章
71
粉丝
142
获赞
5
访问
52.5k
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main() {
int s, n;
while (cin >> s >> n) {
int w[105];
int dp[105][105] = {0};
for (int i = 1; i <= n; i++) {
cin >> w[i];
}
dp[0][0] = 1;////初始化不同了
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= s; j++) {
if (j >= w[i]) {
if (dp[i - 1][j] == 1 || dp[i - 1][j - w[i]] == 1) {
...
登录后发布评论
内层循环改为
for (int j = s; j >= 0; j--)