zoukankan      html  css  js  c++  java
  • HDU2152_Fruit_母函数

    题目大意:                  让你输入n,m,m代表要买m个水果,n表示有n种水果,然后输入n组数据,每组数据有一个s,e.表示每种水果必须要买s到e这么多个。最后要求输出有多少种组合。 解题思路:                   求组合的东西,以后要多想想母函数,直接写出生成函数G(x)=(fru[1].s……fru[1].e)(fru[2].s.……fru[2].e)……(fru[n].s……fru[n].s); 代码:
    #include
    using namespace std;
    const int MAX=105;
    typedef struct q
    {
    	int s;//下限
    	int e;//上限
    }Q;
    int main(void)
    {
    	Q fru[MAX];//水果种类
    	int n,m,i,j,k,c1[MAX],c2[MAX];
    	while(cin>>n>>m)
    	{
    		for(i=1;i<=n;i++)
    			cin>>fru[i].s>>fru[i].e;
    		memset(c1,0,sizeof(c1));
    		memset(c2,0,sizeof(c2));
    		//c1[0]=1;//c1不能等于0,因为第一种水果至少要买fru[1].s个
    		for(i=fru[1].s;i<=fru[1].e;i++)
    			c1[i]=1;
    		for(i=2;i<=n;i++)
    		{
    			for(j=0;j<=m;j++)
    				for(k=fru[i].s;k<=fru[i].e;k++)
    				{
    					c2[j+k]+=c1[j];
    				}
    			for(j=0;j<=m;j++)
    			{
    				c1[j]=c2[j];
    				c2[j]=0;
    			}
    		}
    		cout<
    
     
  • 相关阅读:
    Spring MVC
    Hibernate的状态
    设计模式
    Git在Eclipse中的使用
    深入理解Node.js基于事件驱动的回调
    nodejs核心技术
    webpack使用
    vue各种实例集合
    vue之component
    axios详解
  • 原文地址:https://www.cnblogs.com/cchun/p/2520158.html
Copyright © 2011-2022 走看看