HDOJ2082 找单词

找单词

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

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

1
2
3
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

1
2
7
379297

Source

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

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
#include <limits.h> // include INT_MIN, INT_MAX
#define fadd(i, a, b) for(int (i) = a; (i) <= b; (i)++)
#define fcut(i, a, b) for(int (i) = a; (i) >= b; (i)--)
#define ll long long
#define mem(a) memset((a), 0, sizeof(a))
using namespace std;
const int inf = 0x7f7f7f7f;
const int mod = 1e9 + 7;
const int maxn = 50 + 5;

int b[27];

int deal()
{
int a[27][51];
memset(a, 0, sizeof a);
fadd(i, 0, 26)
a[i][0] = 1;
fadd(i, 1, 26)
fadd(j, 1, 50)
for(int k = 0; k <= b[i] && j - k * i >= 0; k++)
a[i][j] += a[i - 1][j - k * i];
int sum = 0;
fadd(i, 1, 50)
sum += a[26][i];
return sum;
}

int main()
{
freopen("in.txt", "r", stdin);
int n;
scanf("%d", &n);
while(n--)
{
fadd(i, 1, 26)
scanf("%d", &b[i]);
cout << deal() << endl;
}
return 0;
}
eternity6666 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
Donate comment here