HDU 4504 Wei cat series story-Basketball dream (DP)

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4504

 

Question:

Both Chinese and English. However, I only read the hint to understand what it means. An error occurred at the beginning.

Solution:

The maximum number of attacks for a given time is 600, the maximum number of attacks is 600/15 = 40, and the number of attacks we attack is 40/2 = 20. If you want to search in depth,

So the time complexity is O (3 ^ 20), and the time is timed out directly.

I know that dynamic planning is required, but my DP is not working, so I read the online solution report from others.

DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J-2] + dp [I-1] [J-3]; indicates the I times, method for scoring J points

 

First, the score scheme is preprocessed (the preprocessing time is O (20*60 )). When the answer is answered, the attacker will attack t times again, and the solution with a score greater than A and B will add up (the worst time complexity O (60 )).

 

AC code:

1 # include <cstdio> 2 # include <cstring> 3 4 # define times 21 // up to 600/15/2 = 20 times 5 # define score 61 // multiple times 20*3 = 60 Minutes 6 7 typedef _ int64 ll; 8 9 // DP [I] [J] indicates the I th time, casting J-score DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J-2] + dp [I-1] [J-3] 10 int DP [times] [score]; 11 12 Void dynamic () {13 // memset (DP, 0, sizeof (DP); 14 DP [0] [0] = 1; 15 For (INT I = 1; I <times; ++ I) {16 DP [I] [I] = DP [I-1] [I-1]; 17 DP [I] [I + 1] = DP [I-1] [I-1] + Dp [I-1] [I]; 18 19 for (Int J = I + 2; j <= I * 3; ++ J) {20 DP [I] [J] = DP [I-1] [J-1] + dp [I-1] [J-2] + dp [I-1] [J-3]; 21} 22} 23} 24 25 int main () {26 dynamic (); // preprocessing 27 int A, B, T; 28 while (~ Scanf ("% d", & A, & B, & T) {29 t/= 15; // 30 B + = T/2; // Team B's final score: 31 T = (t + 1)/2; // Team A can attack t times: 32 A = B-A + 1; // calculate how many points the Team A has to lose to win the game 33 34 if (a <0) A = 0; // indicates that a has won the competition, and all the cases are added up to 35 36 ll ans = 0; 37 for (INT I = A; I <= T * 3; ++ I) {// Team A's percentage of attacking t times> = a total of 38 ans + = DP [T] [I]; 39} 40 printf ("% i64d \ n ", ans); 41} 42 return 0; 43}

 

HDU 4504 Wei cat series story-Basketball dream (DP)

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.