Title: http://acm.hdu.edu.cn/showproblem.php?pid=5389
Test instructions: Define the number of roots: ① add up each number to get a new number, ② repeat ① until the number only 1 bits. Given the number of n,a,b and n digits, the n number is divided into two parts, so that the number of the sum of the two parts is equal to the number of the sum of the other part of a and the program number of B.
Analysis: A number A of the root s= (A-1)%9+1, in order to facilitate direct use of s=a%9, of which 0 represents 9. The definition Dp[i][j] represents the number of the number of the previous I number of the root of the scheme of J. For the number of I can optionally also can not choose, then the state transfer equation is dp[i][j]=dp[i-1][j] (not selected), dp[i][(J+c[i])%9]+=dp[i-1][j] (optional). Special case is {I:1~n,sigma (C[i])}%9!= (a+b)%9, this situation can not divide the n number into a non-empty two parts satisfying the condition, need a special sentence.
Code:
#include <iostream> #include <cstdio> #include <cstring>using namespace std;const int maxn = 1e5+7; const int mod = 258280327;int dp[maxn][10],c[maxn];int main () {int ncase,n,a,b,i,j;scanf ("%d", &ncase); while ( ncase--) {scanf ("%d%d%d", &n,&a,&b), int sum=0;for (i=1;i<=n;i++) {scanf ("%d", &c[i]); sum+=c[i];} if (sum%9!= (a+b)%9) {if (a%9==sum%9 && b%9==sum%9) printf ("2\n"); else if (a%9==sum%9 | | b%9==sum%9) printf ("1\n"); elseprintf ("0\n"); continue;} Dp[0][0]=1;for (i=1;i<=n;i++) {for (j=0;j<=8;j++) dp[i][j]=dp[i-1][j];for (j=0;j<=8;j++) dp[i][(J+c[i])%9]= (dp[i][(J+c[i])%9]+dp[i-1][j])%mod;} printf ("%d\n", dp[n][a%9]);} return 0;}
Hdu 5389 Zero Escape (DP)