# 【题解】Popping Balls AtCoder Code Festival 2017 qual B E 组合计数

### Step 7

（我想了一整个下午加一整个晚上好叭QAQ）

### Code

#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 2010;
const int MOD = 1e9+7;
int _w;

int C[MAXN][MAXN], sum[MAXN][MAXN], f[MAXN][MAXN];
void prelude() {
for( int i = 0; i < MAXN; ++i ) {
f[i][0] = sum[i][0] = C[i][0] = 1;
for( int j = 1; j <= i; ++j )
C[i][j] = (C[i-1][j] + C[i-1][j-1]) % MOD;
for( int j = 1; j < MAXN; ++j )
sum[i][j] = (sum[i][j-1] + C[i][j]) % MOD;
for( int j = 1; j < MAXN; ++j )
f[i][j] = (f[i][j-1] + sum[i][j]) % MOD;
}
}

int solvet( int t, int b ) {
int ans = 1; // i == 0
for( int i = 1; i <= min(t-1, b); ++i )
ans = int((ans + (ll)f[i-1][t-i-1] * C[b][i]) % MOD);
return ans;
}

int main() {
prelude();
int a, b;
_w = scanf( "%d%d", &a, &b );
if( !a || !b ) return puts("1"), 0;
int ans = 0;
for( int t = 1; t <= a+1; ++t )
ans = (ans + solvet(t, b-1)) % MOD;
printf( "%d\n", ans );
return 0;
}
posted @ 2017-10-20 07:45  mlystdcall  阅读(...)  评论(...编辑  收藏