C. Planar Reflections
考虑dp
dp[i][j]表示i能量的 在第j层的cnt
显然我们会分裂成左右两部分
dp[i][j]=dp[i-1][n-j]+dp[i][j-1]
我们为了不讨论方向问题 直接记忆化搜索即可
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int M = 998244353;
const int mod = 1e9+7;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int n, k;
int dp[1010][1010];
int dfs(int x, int cnt ) {
if(~dp[x][cnt]) return dp[x][cnt];
if(x <= 0) return dp[x][cnt] = 0;
if(cnt <= 0) return dp[x][cnt] = 1;
return dp[x][cnt] = (dfs(x, cnt - 1) + dfs(x - 1, n - cnt)) % mod;
}
void solve(){
cin >> n >> k;
for(int i = 0; i <= n; i ++ )
for(int j = 0; j <= k; j ++ ) dp[j][i] = -1;
cout << dfs(k, n) << endl;
}
signed main(){
fast
int t;t=1;cin>>t;
while(t--) {
solve();
}
return ~~(0^_^0);
}
标签:CodeCraft,const,21,int,Codeforces,711,dp
From: https://www.cnblogs.com/ycllz/p/16806961.html