韩梅梅喜欢满宇宙到处逛街。现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债。韩梅梅手边有104枚来自各个星球的硬币,需要请你帮她盘算一下,是否可能精确凑出要付的款额。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include <queue>
#include <map>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;
const int N = 1e4+10;
const int inf = 10000000;
const int mod = 1e5+10;
typedef long long LL;
vector<int>p[N];
int dp[110], a[N], path[N][110];
int cmp(int x,int y)
{
return x>y;
}
int main()
{
int n, m, x;
scanf("%d %d", &n, &m);
memset(dp,0,sizeof(dp));
memset(path,0,sizeof(path));
dp[0]=1;
for(int i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
sort(a,a+n,cmp);
for(int i=0; i<n; i++)
{
x=a[i];
for(int j=m; j>=x; j--)
{
if(dp[j-x]!=0)
{
dp[j]=1;
path[i][j]=1;
cout<<i<<j<<endl;
}
}
}
if(dp[m]==0) puts("No Solution");
else
{
int i=n-1,j=m, flag=0;
while(i>=0&&j>=0)
{
if(path[i][j])
{
if(flag==0) printf("%d",a[i]),flag=1;
else printf(" %d",a[i]);cout<<i<<j;
j-=a[i];
}
i--;
}
printf("\n");
}
return 0;
}