Fruit HDU - 2152 生成函数基础题
程序员文章站
2022-08-06 20:55:22
还是水题。。这题每个种类数目起点不为0;#include#include#include#includeusing namespace std;typedef long long ll;#define ls (o<<1)#define rs (o<<1|1)#define pb push_backconst int M = 110+...
还是水题。。
这题每个种类数目起点不为0;
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const int M = 110+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
int f[2][M];
int w[M],ns[M],nm[M];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
while(cin>>n>>m)
{
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)cin>>ns[i]>>nm[i],w[i]=1;
f[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=m;j++)f[i&1][j]=0;
for(int k=ns[i];k<=nm[i];k++)//当前种类水果选几个
for(int x=0;x+k*w[i]<=m;x++)
f[i&1][x+k*w[i]]+=f[(i-1)&1][x];
//cout<<i<<" "<<x<<" "<<k<<" "<<x+k*w[i]<<" - - "<<f[i&1][x+k*w[i]]<<" - > "<<f[(i-1)&1][x]<<endl;;
}
cout<<f[n&1][m]<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/bjfu170203101/article/details/107593661