[Hackercup Round1 3] Winning at Sports (Dynamic planning)

Source: Internet
Author: User

Title Link: https://www.facebook.com/hackercup/problems.php?pid=688426044611322&round=344496159068801

The main topic: Two kinds of win, one is called Stress-free, the other is called stressful. Ask you what the number of stress-free and stressful will be given for the final result.

Established status: Dp[i][j] represents the score for I-J when the number of stress-free, a state shift: dp[i][j] = dp[i-1][j]+dp[i][j-1]

Because if the score is i-1:j, then we add a game, add a point to i-1, still meet Stress-free.

The same i:j-1 is also the same: because I is strictly greater than J, so we add a point to j-1, the other side of the total disk is J, because i:j-1, the middle process always meet I ' >j-1 ', so adding a point does not affect the satisfaction of test instructions.

The final result exists in dp[a][b].

Established status: F[i][j] represents the score for I-J, i≥j the number of disks. This is done because it is equivalent to the test instructions requirement.

The state transition equation is unchanged, but the transferred boundary becomes i≥j.

The final answer is F[B][B]

1#include <cstdio>2#include <algorithm>3#include <cstring>4 using namespacestd;5 6 Const intMOD = +* +* ++7;7 Const intMax_n =2222;8 intDp[max_n][max_n];9 intF[max_n][max_n];Ten intT; One intb; A  - intMain () { - //freopen ("Input.txt", "R", stdin); the //freopen ("Output.txt", "w", stdout); -Memset (DP,0,sizeof(DP)); -Memset (F,0,sizeof(f)); -      for(intI=1; i<= -; i++){ +dp[i][0] =1; -     } +      for(intI=2; i<= -; i++){ A          for(intj=1; j<i;j++){ atDP[I][J] = (dp[i][j-1]+dp[i-1][J])%MOD; -         } -     } -      for(intI=0; i<= -; i++){ -f[i][0] =1; -     } in      for(intI=1; i<= -; i++){ -          for(intj=1; j<=i;j++){ toF[I][J] = (f[i][j-1]+f[i-1][J])%MOD; +         } -     } thescanf"%d",&T); *      for(intCases =1; Cases <= T; cases++){ $scanf"%d-%d",&a,&b);Panax Notoginsengprintf"Case #%d:%d%d\n", Cases,dp[a][b],f[b][b]); -     } the     return 0; +}

[Hackercup Round1 3] Winning at Sports (Dynamic planning)

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.