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)