HDU 2082-find a word (primary function), hdu2082-word Function

Source: Internet
Author: User

HDU 2082-find a word (primary function), hdu2082-word Function
Search for wordsTime Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission (s): 4208 Accepted Submission (s): 3023


Problem Description assume there are x1 letters A and x2 letters B ,..... assume that the value of letter A is 1, and the value of letter B is 2 ,..... the value of Z is 26. How many words <= 50 can be found for a given letter? The value of a word is the sum of the values of all the letters of a word. For example, the value of word ACM is 1 + 3 + 14 = 18, the value of HDU is 8 + 4 + 21 = 33. (The words are irrelevant to the order. For example, ACM and CMA think they are the same word ).
 
Input is an integer N, which represents the number of test instances.
Then there are N rows of data. Each row contains 26 <= 20 integers x1, x2,... x26.
 
Output for each test instance, please Output the total value <= 50 words, each instance Output occupies a line.
Sample Input

21 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 09 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
7379297 .. The upper limit is 50. After an array is generated, it is added from 1 to 50 to all combinations.
#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\n",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;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.