CodeCraft-21 and Codeforces Round #711 C

C. Planar Reflections

考虑dp
dp[i][j]表示i能量的在第j层的cnt
显然我们会分裂成左右两部分 显然我们这里是要分方向的
但是可以把向左的部分 找到对称点之后 就相当于向右了 所以我们可以少维护一维
dp[i][j]=dp[i-1][n-j+2]+dp[i][j+1]
注意这里我们的下标从1开始所以是n-j+2
当然我们的初始化就是dp[i][n+1]要是已经出了最右边就是1
最后我们的答案就是dp[k][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 dp[1010][1010];//i能级j层的cnt
void solve(){
    int n,k;cin>>n>>k;
    for(int i=1;i<=k;i++)dp[i][n+1]=1;
    for(int i=1;i<=k;i++)
        for(int j=n;j>=1;j--)
            (dp[i][j]=dp[i][j+1]+dp[i-1][n-j+2])%=mod;
    cout<<dp[k][1]<<endl;
}
signed main(){
    fast
    int t;t=1;cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}
posted @ 2022-10-19 16:53  ycllz  阅读(22)  评论(0)    收藏  举报