Hdoj HDU 2082 find the word ACM 2082 in HDU

Source: Internet
Author: User
Miyu original, post Please note: Reprinted from __________ White House

Question address:
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2082
Description: 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 much value can be found for a given letter? <= What about 50 words? 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
The input is an integer N, indicating the number of test instances.
Then there are n rows of data, and each row contains 26<=Integer x1, x2,... x26.
 

Output
For each test instance, output the total value that can be found<=The number of words in 50, and the output of each instance occupies one line.
 

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


Question Analysis:
There is a very standard primary function question (for more information about the primary function, see <primary function details> ). however, this question can be properly optimized. Because the data is input in 26 data orders, rather than sparse polynomials, you can simply input one variable.

CodeAs follows:Miyu original, post Please note: Reprinted from __________ White House

# Include < Iostream >
Using   Namespace STD;
Int Num1 [ 51 ];
Int Num2 [ 51 ];
Int Main ()
{
Int T;
While (CIN > T)
{
While (T -- )
{
Memset (num1, 0 , Sizeof (Num1 ));
Memset (num2, 0 , Sizeof (Num2 ));
Num1 [ 0 ] =   1 ;
For ( Int I =   1 ; I <=   26 ; ++ I)
{
Int CNT;
CIN > CNT;
If (CNT =   0 )
{
Continue ;
}
For ( Int J =   0 ; J <=   50 ; ++ J)
{
For ( Int K =   0 ; K <= CNT && K * I + J <=   50 ; K ++ )
{
Num2 [K * I + J] + = Num1 [J];
}
}
For ( Int J =   0 ; J <=   50 ; ++ J)
{
Num1 [J] = Num2 [J];
Num2 [J] =   0 ;
}
}
Int Total =   0 ;
For ( Int I =   1 ; I <=   50 ; ++ I)
{
Total + = Num1 [I];
}
Cout < Total < Endl;
}
}
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.