hdoj 2082 找单词 <构造出了 --- 真正de母函数>
2016-07-22 09:36
771 查看
找单词
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6133 Accepted Submission(s): 4305
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程序设计期末考试
构造(1+x)*(1+x^2)* (1+x^3 ) * .................* ( 1+x^n)
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL shu[60],p[30][60];
int ge,xiang[6000],a;
int main()
{
int t;scanf("%d",&t);
while (t--)
{
memset(shu,0,sizeof(shu));
memset(p,0,sizeof(p));
shu[0]=1;ge=0;
for (int i=1;i<=26;i++)
{
scanf("%d",&a);
xiang[i]=a;
}
for (int i=1;i<27;i++)
{
int kk=xiang[i];
p[i][0]=1;
<span style="color:#33cc00;">for (int j=0;j<kk;j++)
{
for (int k=50;k-i>=0;k--)
p[i][k]+=p[i][k-i];
}</span>
for (int j=1;j<=50;j++)
if (p[i][j])
p[i][j]=1;//消(1+ x^i)^n中的相同组
<span style="color:#ff6666;">for (int j=50;j>=0;j--)
{
for (int k=1;k+j<=50;k++)
shu[j+k]+=shu[j]*p[i][k];
}</span>
}
long long s=0;
for (int i=1;i<=50;i++)
s+=shu[i];
printf("%lld\n",s);
}
return 0;
}
相关文章推荐
- 位运算
- caffe手写数字mnist训练测试使用教程
- JAVA字符串格式化-String.format()的使用
- aba
- LintCode(容易)55.比较字符串
- web项目发布相关
- Valid Palindrome leetcode
- Ajax分页插件Pagination从前台jQuery到后端java总结
- Windows环境下React Native环境配置详解!!!
- 无线实战视频
- It's All In The Mind
- qDebug("record:" record) and qDebug() << "record:" << record;
- 就算失业,这些工作也不想去!
- Android APK文件安装过程小结
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
- (转)计算机科学中最重要的32个算法,人工智能里用到很多
- String中“==”和equals的区别
- 2014十大的安全工具(ToolsWatch.org投票选出)
- aaa
- 小曹学SOA1——web服务平台体系架构(WSPA)