欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

HDU1085 —— 生成函数入门题

程序员文章站 2022-06-28 21:54:29
(1+X^i)*……最经典的生成函数。#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 = 1e4+7...

(1+X^i)*……

最经典的生成函数。

#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 = 1e4+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[4][M];
int w[4]={0,1,2,5};
int vs[M],nm[4];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	while(1)
	{
		cin>>nm[1]>>nm[2]>>nm[3];
		if(nm[1]==0&&nm[2]==0&&nm[3]==0)break;
	  	vector<int>v;
	  	v.pb(0);
	  	memset(f,0,sizeof(f));
	  	memset(vs,0,sizeof(vs));
	  	f[0][0]=vs[0]=1;
	  	for(int i=1;i<=3;i++)
	  	{
	  		vector<int>tp;
	  		for(auto x:v)
	  		{
	  			for(int k=0;k<=nm[i];k++)
	  			{
	  			//	cout<<i<<" "<<x<< "  "<<k<<" "<<x+k*w[i]<<endl;
	  				f[i][x+k*w[i]]+=f[i-1][x];
	  				if(!vs[x+k*w[i]])vs[x+k*w[i]]=1,tp.pb(x+k*w[i]);
					  //cout<<"==-=-=    "<<x+k*w[i]<<endl;;
				}
			}
			for(auto x:tp)v.pb(x);
		}
		for(int i=1;i<=10000;i++)if(f[3][i]==0){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

 

本文地址:https://blog.csdn.net/bjfu170203101/article/details/107592665