HDU 5389 Zero Escape (2015-year school joint eighth dynamic Planning)

Source: Internet
Author: User

Topic Connection: Portal

Test instructions

A sequence of length n is divided into two groups, making a set of and a, a group of and b.

Note here and define the number of these numbers as the root.

A number of the root of the calculation formula for, root = (x-1)%9+1;

It is obvious that the root of a positive integer is 1~9 analysis, if the number of n is divided into two groups,

The number of a group of Roots is a, the number of a group is B then the sum of the numbers of the two groups is equal to (a+b)

Number of roots. So we just need to consider the case of composing one of the numbers, and then we'll make a final

judgment can we set DP[I][J] to indicate that the number of the first I number consists of the number of J.

Note any one of these groups can be empty.

The code is as follows:

#include <iostream> #include <cstring> #include <cstdio> #include <algorithm>using namespace Std;typedef Long long ll;const LL mod = 258280327;const int maxn = 1e5+10;    LL dp[2][10];int A[maxn];int Main () {int t,a,b,n;    scanf ("%d", &t);        while (t--) {scanf ("%d%d%d", &n,&a,&b);        int sum=0;            for (int i=1;i<=n;i++) {scanf ("%d", a+i);        Sum= (sum+a[i]-1)%9+1;        } int cur=0;        Memset (Dp,0,sizeof (DP));        Dp[0][0]=1;            for (int i=1;i<=n;i++) {cur^=1;            memset (dp[cur],0,sizeof (dp[cur));                for (int j=0;j<10;j++) {dp[cur][j]= (dp[cur][j]+dp[cur^1][j])%mod;                int t = (j+a[i]-1)%9+1;            Dp[cur][t]= (Dp[cur][t]+dp[cur^1][j])%mod;        }} int tot = (a+b-1)%9+1;        LL ans = 0;            if (tot = = SUM) {Ans=dp[cur][a];        if (a==sum) ans--;        } if (a==sum) ans++; if (b==sum) ans++;    printf ("%i64d\n", ans); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5389 Zero Escape (2015-year school joint eighth 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.