Yahoo Programming Contest 2019 F - Pass

F - Pass

思路:

dp[i][j] 表示到第 i 个球为止放了 j 个蓝球的方案数

第 i 个球来自的位置的最右边是min(i, n)

转移方程看代码

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 2e3 + 10; 
const int MOD = 998244353;
char s[N];
int dp[N*2][N*2];
int sum[N], sm[N];
int main() {
    int n;
    scanf("%s", s+1);
    n = strlen(s+1);
    for (int i = 1; i <= n; ++i) sum[i] = sum[i-1] + s[i]-'0';
    dp[0][0] = 1;
    for (int i = 1; i <= 2*n; ++i) {
        int p = min(i, n);
        for (int j = 0; j < i; j++) {
            if(sum[p] > j) dp[i][j+1] = (dp[i][j+1] + dp[i-1][j]) % MOD;
            if(2*i - sum[p] > i-1-j) dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD; 
        }
    } 
    printf("%d\n", dp[2*n][sum[n]]);
    return 0;
}

 

posted @ 2019-02-11 21:15  Wisdom+.+  阅读(166)  评论(0编辑  收藏  举报