HDU 5389 Zero Escape (DP + scrolling array)

Source: Internet
Author: User

Zero EscapeTime limit:2000/1000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 864 Accepted Submission (s): 438


Problem Descriptionzero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (your may hear about EV Er17?) and developed by Chunsoft.

Stilwell is enjoying the first chapter of this series, and in this chapter digital root are an important factor.

The definition of digital root on Wikipedia:
The digital root of a non-negative integer is the digit value obtained by an iterative process of summing digits, O n each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root ofIs, becauseand.

In the game, every player has a special identifier. Maybe players has the same identifier, but they is different players. If a group of players want to get into a door numbered, the digital root of their identifier sum must be.
For example, playersCan get into the door, but playersCan ' t.

There is doors, numberedand. Maybe, but they is and different door.
And there isPlayers, everyone must get into one of these and doors. Some players'll get into the door, and others'll get into the door.
For example:
Players is,,
There is one-to-distribute the Players:all players get into the door. Because There is no player to get into the doorThe digital root limit of this door would be ignored.

Given The identifier of every player, please calculate how many kinds of methods is there,.
Inputthe first line of the input contains a single number, the number of test cases.
For each test case, the first line contains three integers,and.
Next Line containsIntegers, describing the identifier of every player.
,,,
Outputfor each test case, output a single integer with a single line, the number of ways that thesePlayers can get into these and doors.
Sample Input
43 9 11 2 63 9 12 3 35 2 31 1 1 1 19 9 91 2 3 4 5 6 7 8 9

Sample Output
101060

Authorsxyz
Source2015 multi-university Training Contest 8


Test instructions: give n personal ID, there are two doors, each door has a label, we remember as A and B, now we want to divide n individuals into two groups. Enter two doors, so that the two parts of the label and (the iteration of the request, until become a number) each equals A and B, ask how many kinds of division, (can all the people into a door).


Click to open link


PT = J-p[i];

State transition equation: dp[i][j] = Dp[i-1][j] + dp[i-1][pt];

Two methods of processing:


One

#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h>using namespace Std;const int N = 100001;const int mod = 258280327;int dp[n][10];int n,a,b;int p[n];int num (i    NT Xx,int yy) {int t = xx + yy;    if (t%9 = = 0) {return 9; } return t%9;}    int pnum (int xx,int yy) {int tt = XX-YY;    if (tt%9 = = 0) {return 9;    } if (tt%9<0) {return + + (tt%9); } return tt%9;}    int main () {int T;    scanf ("%d", &t);        while (t--) {int sum = 0;        scanf ("%d%d%d", &n,&a,&b);            for (int i=1;i<=n;i++) {scanf ("%d", &p[i]);        sum = num (sum,p[i]);        } memset (Dp,0,sizeof (DP));        Dp[0][0] = 1;                for (int i=1;i<=n;i++) {for (int j=0;j<=9;j++) {Dp[i][j] + = dp[i-1][j];                DP[I][J] = Dp[i][j]%mod;                int pt = Pnum (J,p[i]);if (pt = = 9) {Dp[i][j] + = max (dp[i-1][0],dp[i-1][9]);                } else {Dp[i][j] + = Dp[i-1][pnum (J,p[i]);            } Dp[i][j] = Dp[i][j]%mod;        }} int ans = 0;            if (num (b) = = sum) {ans = dp[n][a];            if (a = = sum) {ans--;        }} if (a = = sum) {ans++;        } if (b = = sum) {ans++;    } printf ("%d\n", ans); } return 0;}



Two


#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < stdlib.h>using namespace Std;const int N = 100001;const int mod = 258280327;int dp[n][10];int n,a,b;int p[n];int num (i    NT Xx,int yy) {int t = xx + yy;    if (t%9 = = 0) {return 9; } return t%9;}    int main () {int T;    scanf ("%d", &t);        while (t--) {int sum = 0;        scanf ("%d%d%d", &n,&a,&b);            for (int i=1;i<=n;i++) {scanf ("%d", &p[i]);        sum = num (sum,p[i]);        } memset (Dp,0,sizeof (DP));        Dp[0][0] = 1;                for (int i=1;i<=n;i++) {for (int j=0;j<=9;j++) {int pt = num (j,p[i]);                DP[I][J]+=DP[I-1][J];                DP[I][PT]+=DP[I-1][J];                Dp[i][j]%=mod;            Dp[i][pt]%=mod;        }} int ans = 0;            if (num (b) = = sum) {ans = dp[n][a];if (a = = sum) {ans--;        }} if (a = = sum) {ans++;        } if (b = = sum) {ans++;    } printf ("%d\n", ans); } return 0;}



HDU 5389 Zero Escape (DP + scrolling array)

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.