#include <iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int n,x;
int kinds[2000005];//kind[i]表示构成i元的方法数
int mykinds[2000005];
int value[205];
int result[205];
int main()
{
cin >> n >> x;
memset( kinds, 0, sizeof(kinds) );
for( int i = 0; i < n; i++ )
{
cin >> value[i];
for( int j = x; j >= value[i]; j-- )
{
kinds[j] += kinds[j-value[i]];
}
kinds[value[i]]++;
}
int cnt = 0;
for( int i = 0; i < n; i++ )//去掉value[i]
{
memset( mykinds, 0, sizeof(mykinds) );//初始化需要注意
mykinds[0] = 1;
for( int j = 1; j <= x; j++ )
{
if( j >= value[i] )
mykinds[j] = kinds[j] - mykinds[j-value[i]];
else
mykinds[j] = kinds[j];
}
if( mykinds[x] ==0 )
{
result[cnt++] = value[i];
}
}
sort( result, result+cnt );
cout << cnt <<endl;
if(!cnt)
cout<<endl;
else
{
for( int i = 0; i < cnt-1; i++ )
cout << result[i] <<' ';
cout << result[cnt-1] <<endl;
}
return 0;
}
动态规划之硬币
最新推荐文章于 2022-07-03 20:31:17 发布