hdu 5389(dp)

#include<stdio.h>
#include<string.h>

const int N = 100008;
const int MOD = 258280327;

int arr[N];
int dp[N][16];

int main()
{
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int n, a, b;
        scanf("%d%d%d", &n, &a, &b);
        int root = 0;

        for(int i = 1; i <= n; i++){
            scanf("%d", &arr[i]);
            root += arr[i];
        }
        root = (root - 1) % 9 + 1;
        memset(dp, 0, sizeof(dp));
        int ans = 0;
        int rab = (a+b-1) % 9 + 1;
        if(root != rab)
        {
            if(root == a)
                ans ++;
            if(root == b)
                ans ++;
            printf("%d\n", ans);
            continue;
        }
        else
        {
            dp[0][0] = 1;
            for(int i = 1; i <= n; i++)
            {
                for(int j = 0; j <= 9; j++)
                {
                    int t = (j + arr[i] - 1) % 9 + 1;
                    dp[i][j] += dp[i-1][j];
                    dp[i][t] += dp[i-1][j];
                    dp[i][j] %= MOD;
                    dp[i][t] %= MOD;
                }
            }
            int ans = dp[n][a];
            if(b == root)
                ans ++;
            printf("%d\n", ans);

        }

    }

    return 0;
}

發佈了49 篇原創文章 · 獲贊 9 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章