HDU 4972 A Simple Dynamic Programming Problem (conversion of confused thinking questions) 2014 multi-school 10

Source: Internet
Author: User

Question Link

A given Array records the score difference between two teams, with only a score difference. It does not indicate who is tall or who is low, and asks how many possible scores are finally scored.

Analysis:

Similar to the question of CF, I didn't think about it during the competition. It was so stupid .....

1 # include <iostream> 2 # include <cstdio> 3 # include <cstring> 4 # include <cstdlib> 5 # include <cmath> 6 # include <vector> 7 # include <algorithm> 8 # define ll _ int64 9 const int maxn = 100000 + 10; 10 using namespace STD; 11 int A [maxn]; 12 13 int main () 14 {15 int I, t, n, CA = 1, ANS, F; 16 scanf ("% d", & T); 17 while (t --) 18 {19 ans = 0; F = 0; 20 scanf ("% d ", & N); 21 for (I = 1; I <= N; I ++) 22 {23 scanf ("% d", & A [I]); 24 if (I> = 2) 25 {26 if (a [I-1] = 1 & A [I] = 2) 27 ans ++; 28 if (a [I-1] = 2 & A [I] = 1) 29 ans ++; 30 if (a [I-1] = A [I] & A [I]! = 1) // these two are not compliant with the rule 31 f = 1; 32 If (ABS (A [I]-A [I-1])> 3) 33 F = 1; 34} 35} 36 IF (f) 37 printf ("case # % d: 0 \ n", CA ++ ); // null case 38 else if (a [n] = 0) 39 printf ("case # % d: % d \ n", CA ++, ans + 1); // the final score difference is 0, and the result is half less. 40 else41 printf ("case # % d: % d \ n", CA ++, 2 * ans + 2); 42} 43 return 0; 44}

 

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.