您的位置:首页 > 其它

hdu 2082 找单词 母函数

2016-06-13 19:38 369 查看


找单词

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 5938    Accepted Submission(s): 4169


Problem Description

假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26。那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33。(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词)。

 

Input

输入首先是一个整数N,代表测试实例的个数。

然后包括N行数据,每行包括26个<=20的整数x1,x2,.....x26.

 

Output

对于每个测试实例,请输出能找到的总价值<=50的单词数,每个实例的输出占一行。

 

Sample Input

2
1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
9 2 6 2 10 2 2 5 6 1 0 2 7 0 2 2 7 5 10 6 10 2 10 6 1 9

 

Sample Output

7
379297

 

Source

2006/1/15 ACM程序设计期末考试

 

Recommend

lcy   |   We have carefully selected several similar problems for you:  2079 1085 1171 1398 2152 

 

Statistic | Submit | Discuss | Note

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define for0(a, n) for (int (a) = 0; (a) < (n); (a)++)
#define for1(a, n) for (int (a) = 1; (a) <= (n); (a)++)
typedef long long ll;
typedef pair<int, int> pii;
const int INF =0x3f3f3f3f;
const int maxn= 50 ;
const int N= 26 ;

int a[2][maxn+10];//系数,滚动数组,母函数,

void work()
{
memset(a[0],0,sizeof a[0]);
a[0][0]=1;
int num;
int now=1,nex=0;//a[now]保存计算累计的结果,a[nex]表示临时的。
for1(i,N)
{
now^=1;
nex^=1;
scanf("%d",&num);

memset(a[nex],0,sizeof a[nex]);
for(int add=0;add<=min(maxn,num*i);add+=i)
{
for(int j=maxn;j>=add;j--)
{
a[nex][j]+=a[now][j-add];
}

}
}
int ans=0;
for0(i,maxn+1) ans+=a[nex][i];
printf("%d\n",ans-1);//有一个是一个单词都不选

}
int main()
{
int T;scanf("%d",&T);
while(T--)
{
work();
}

return 0;
}
/*
23
1 1 1
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: