1 条题解
-
1HLBhahaqiu LV 8 MOD @ 2020-08-29 16:53:41
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for (int i=1;i<=n;i++)
#define REP(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pos(x,y) (x+(y)*n)
const int N=100000+10;
const int inf=0x3f3f3f3f;
const ll mod=7777777;
const double eps=1e-8;
int w;
int n;
int a[105];
int f[105][100*1000+1];
int p[105][100*1000+1];
bool remain[105];
int main() {
scanf("%d %d",&w,&n);
FOR(i,n) scanf("%d",&a[i]);
f[0][0]=1;
FOR(i,n) REP(j,0,w)
{
f[i][j]=f[i-1][j]+(j>=a[i]?f[i-1][j-a[i]]:0);
}
if (f[n][w]==0) {
cout<<0<<endl;
return 0;
} else if (f[n][w]>1) {
cout<<-1<<endl;
return 0;
} else {
int x=n,y=w;
while (y) {
if (f[x-1][y]==0) {
remain[x]=1;
y-=a[x];
x--;
} else x--;
}
}
FOR(i,n) if (!remain[i]) cout<<i<<" ";
cout<<endl;
return 0;
}
- 1