当前位置: 移动技术网 > 移动技术>移动开发>IOS > HDU - 2082 生成函数基础题

HDU - 2082 生成函数基础题

2020年07月28日  | 移动技术网移动技术  | 我要评论

这些题都可以暴力直接做,但用于练习生成函数。(虽然并没有。。。马上做几道难题练练)

#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 = 50+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[30],nm[30];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int T;
  	cin>>T;
  	while(T--)
	{
		memset(f,0,sizeof(f));
		for(int i=1;i<=26;i++)cin>>nm[i],w[i]=i;
	  	f[0][0]=1;
	  	int n=50;
	  	for(int i=1;i<=26;i++)
	  	{
	  		for(int j=0;j<=n;j++)f[i&1][j]=0;
	  		for(int k=0;k<=nm[i];k++)//当前种类字母选几个 
	  			for(int x=0;x+k*w[i]<=n;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;;
		}
		ll ans=0;
		for(int i=1;i<=50;i++)ans+=f[26&1][i];
		cout<<ans<<endl;
	}
	return 0;
}

 

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网