![](http://acm.fzu.edu.cn/image/problem.gif)
Problem Description
遥远的YS星球上,生活着两种物种名为Yellow和Star,简称物种Y和物种S。
神奇的是物种Y的体重始终为50kg,物种S的体重始终为100kg。
这天,n只生物结伴出行,在路途中,它们被一条长长的河流挡住了去路。所幸岸边停靠着一条船,船上写着:负重m kg。
YS星球上的物种有很强的时间观念,它们需要找出一种最快的方案过河:
1、要开船每次至少要有一只生物在船上
2、载着的生物总重量不能超过船的负重m
3、无论载多少只生物,船每次从岸边到另一岸边需要的时间相同,并且不考虑中间换乘时间(换句话说,要求的是最少的开船次数)
请你帮助这些Yellow、Star们,找出最少的开船次数,并且求出最少次数下的有多少种不同的方案数。
当存在某轮开船时,两个方案乘客的集合不同,认为这两个方案是不同的。
Input
Output
输出两行,第一行为最少开船次数,第二行为不同方案数,由于方案数可能很大,对1000000007(10^9+7)取模后输出。
Sample Input
Sample Output
Hint
最优的两种情况为:
1和2过去,1回来,3过去,2回来,1和2过去。
1和2过去,2回来,3过去,1回来,1和2过去。
设d[k][i][j]为第k次,岸上(不是对岸)重量为50的人数为i,100的人数为j。
k为奇数时,岸上的过去,d[k][i][j]+=d[k-1][i+x][j+y]*c[i+x][x]*c[j+y][y]
k为偶数时,对岸的人过来,d[k][i][j]+=d[k-1][i-x][j-y]*c[cnta-i+x][x]*c[cntb-j+y][y] cnta,cntb分别为50,100的人的个数
边界处理一下,就好,初始的时候 d[0][cnta][cntb]=1.
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <set>
#include <queue>
using namespace std;
const int INF=1e9+10;
const double EPS = 1e-10;
typedef long long ll;
const int mod=1e9+7;
ll d[105][105][105];
ll c[55][55];
int main(){
//freopen("out.txt","w",stdout);
int n,w;
for(int i=0;i<52;i++){
c[i][0]=1;
for(int j=1;j<52;j++)
c[i][j]=(1LL*c[i-1][j]+c[i-1][j-1])%mod;
}
//cout<<"c "<<c[6][2]<<endl;
while(scanf("%d %d",&n,&w)!=EOF){
int cnta=0,cntb=0;
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
if(x==50) cnta++;
else cntb++;
}
memset(d,0,sizeof(d));
d[0][cnta][cntb]=1;
ll ans1=0,ans2=0;
for(int k=1;k<100;k++){
if(k&1){
for(int i=0;i<=cnta;i++)
for(int j=0;j<=cntb;j++)
for(int x=0;i+x<=cnta;x++)
for(int y=0;j+y<=cntb;y++){
if(w<(50*x)+(100*y)) continue;
if(x==0&&y==0) continue;
d[k][i][j]+=1LL*d[k-1][i+x][j+y]*c[i+x][x]*c[j+y][y];
d[k][i][j]%=mod;
}
}else{
for(int i=0;i<=cnta;i++)
for(int j=0;j<=cntb;j++)
for(int x=0;x<=i;x++)
for(int y=0;y<=j;y++){
if(w<(50*x)+(100*y)) continue;
if(x==0&&y==0) continue;
d[k][i][j]+=1LL*d[k-1][i-x][j-y]*c[cnta-i+x][x]*c[cntb-j+y][y];
d[k][i][j]%=mod;
}
}
if(d[k][0][0]>0){
ans1=k;
ans2=d[k][0][0];
break;
}
}
printf("%I64d\n%I64d\n",ans1,ans2 );
}
return 0;
}