题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6092
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 1e4 + ;
int b[maxn] , dp[maxn] , n , m;
int main() {
int t;
scanf("%d", &t);
while(t--) {
scanf("%d%d" , &n , &m);
for (int i = ; i <= m; i++) {
scanf("%d" , &b[i]);
dp[i] = ;
}
dp[] = ;
int count = ;
for (int i = ; i <= m; i++) {
while (dp[i] < b[i]) {
count++;
if(count != n) printf("%d " , i);
else printf("%d\n" , i);
for (int j = m ; j >= i ; j--) {
dp[j] += dp[j - i];
}
}
}
}
return ;
}
题解:就是一道多重背包,每次有优先拿最小的来更新看代码就很好理解了。