#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
const ll MOD=(ll)1e9+7;
const int inf=(ll)1e9;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,w;
int a[211];
int sum[202];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout<<fixed;
#ifdef LOCAL_DEFINE
FILE *stream1;
stream1=freopen("in","r",stdin);
if(stream1==NULL)return 0;
#endif
cin>>n>>w;
for(int i=0;i<n;i++){
cin>>a[i];
}
a[n]=inf;
n++;
sort(a,a+n);
ll ans=0;
for(int i=0;i<n+1;i++){
int sum=0;
for(int j=0;j<i;j++){
sum+=a[j];
}
int nokori=w-sum;
if(nokori<0)continue;
int minw=a[i];
ll dp[2][10001];
for(int j=0;j<2;j++)for(int k=0;k<=w;k++)dp[j][k]=0;
dp[(i+1)&1][0]=1;
for(int j=i+1;j<n;j++){
for(int k=0;k<=w;k++){
dp[(j+1)&1][k]=0;
}
for(int k=0;k<=w;k++){
if(dp[j&1][k]==0)continue;
if(k+a[j]<=nokori){
dp[(j+1)&1][k+a[j]]=(dp[(j+1)&1][k+a[j]]+dp[j&1][k])%MOD;
}
dp[(j+1)&1][k]=(dp[(j+1)&1][k]+dp[j&1][k])%MOD;
}
}
for(int j=0;j<=nokori;j++){
if(nokori-j<minw)ans=(ans+dp[n&1][j])%MOD;
}
}
cout<<ans<<endl;
#ifdef LOCAL_DEFINE
cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
fclose(stream1);
#endif
return 0;
}
- 数え上げはもれなくダブりなくを意識したい。
- 今回はソートして初めて鞄に入れられなかった小人で場合分けをする。これはもれなくダブりのない場合わけである。
- ソートをする理由は、ソートをせずにナップザックのようなことをすると、もう鞄の中にどんな小人も入る事ができないかどうかの判定ができないからである。