http://acm.hdu.edu.cn/showproblem.php?pid=2152
//1307251 2009-04-25 10:56:01 Accepted 2152 0MS 260K 527 B C++ no way
#include<iostream>
using namespace std;
int main()


{
int n,M;
while(cin>>n>>M)

{
int i,j,k;
int most[101],least[101],num[101],temp[101];
for(i=1;i<=n;i++)
cin>>least[i]>>most[i];
for(i=0;i<=M;i++)
temp[i] = num[i] = 0;
num[0] = 1;
for(i=1;i<=n;i++)

{
for(j=0;j<=M;j++)

{
for(k=least[i];k<=most[i] && k+j<=M;k++)
temp[j+k] += num[j];
}
for(j=0;j<=M;j++)

{
num[j] = temp[j];
temp[j] = 0;
}
}
cout<<num[M]<<endl;
}
return 0;
}










































now[0]=1;
for( i=least[1]; i<=most[1]; ++i ) now[i]=1;
for( i=2; i<=n; ++i ){...
}
為什么這樣是WA???
確實是錯了,我也沒怎么想明白
不過你那樣寫后
for(j=0;j<=M;j++)//是不是少了這層循環(huán)對第一種水果而言
for( i=least[1]; i<=most[1]; ++i ) ……