zoukankan      html  css  js  c++  java
  • HDU 2082-找单词(母函数)

    找单词

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4208    Accepted Submission(s): 3023


    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
    恩 。。非常水的母函数了,上限为50,生成数组后从1加到50就是全部的组合
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <string>
    #include <cctype>
    #include <vector>
    #include <cstdio>
    #include <cmath>
    #include <deque>
    #include <stack>
    #include <map>
    #include <set>
    #define ll long long
    #define maxn 1010
    #define pp pair<int,int>
    #define INF 0x3f3f3f3f
    #define max(x,y) ( ((x) > (y)) ? (x) : (y) )
    #define min(x,y) ( ((x) > (y)) ? (y) : (x) )
    using namespace std;
    int n,v[27],a[66],b[66],num[27];
    void solve()
    {
    	memset(a,0,sizeof(a));a[0]=1;
    	for(int i=0;i<26;i++)
    	{
    		memset(b,0,sizeof(b));
    		for(int j=0;j<=num[i]&&j*v[i]<=50;j++)
    			for(int k=0;k+j*v[i]<=50;k++)
    				b[k+j*v[i]]+=a[k];
    			memcpy(a,b,sizeof(b));
    
    	}
    	int ans=0;
    	for(int i=1;i<=50;i++)
    		ans+=a[i];
    	printf("%d
    ",ans);
    }
    int main()
    {
    	int T;
    	for(int i=0;i<26;i++)
    		v[i]=i+1;
    	scanf("%d",&T);
        while(T--)
    	{
    		for(int i=0;i<26;i++)
    			scanf("%d",&num[i]);
    		solve();
    	}
    	return 0;
    }
  • 相关阅读:
    设计模式——装饰模式(Decorator Pattern)
    设计模式——策略模式(Strategy Pattern)
    设计模式——简单工厂模式(SimpleFactory Pattern)
    入博客园三周年记
    android+Service
    surfaceView+canvas+paint+bitmap
    Enable Sublime text 2 to support GBK in Mac
    androidstudio+opencv
    mac下的环境变量PATH
    Curl命令
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4553842.html
Copyright © 2011-2022 走看看