首页 > 其他分享 >CodeCraft-21 and Codeforces Round #711 C

CodeCraft-21 and Codeforces Round #711 C

时间:2022-10-19 17:02:48浏览次数:51  
标签:CodeCraft const 21 int Codeforces 711 dp

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

相关文章

  • 2021长安杯复盘学习
    目录检材一检材二检材三检材四检材五解压密码:2021第三届CAB-changancup.com给的文件都是VC加密过的,所以要先拿密码挂载一下建议挂载完把里面的镜像移到自己硬盘里0.0......
  • [GKCTF2021]random
    [GKCTF2021]random本题出现了MT19937伪随机数生成算法。目录[GKCTF2021]random题目分析MT19937算法步骤代码实现解法1解法2总结题目task.pyimportrandomfromhashli......
  • [GKCTF2021]RRRRSA
    [GKCTF2021]RRRRSA题目fromCrypto.Util.numberimport*fromgmpy2importgcdflag=b'xxxxxxxxxxxxx'p=getPrime(512)q=getPrime(512)m=bytes_to_long(fl......
  • 21、如何分析一个开源项目
    ......
  • 2021年非常全的.NET Core面试题
    1.如何在ASP.NETCore中激活Session功能?          首先要添加session包.其次要在configservice方法里面添加session。然后又在configure方法里面调用usese......
  • leetcode-217-easy
    ContainsDuplicate思路一:Set检测publicstaticbooleancontainsDuplicate(int[]nums){Set<Integer>set=newHashSet<>();for(intnum:nums){......
  • leetcode-219-easy
    ContainsDuplicateII思路一:for循环遍历,结果超时publicbooleancontainsNearbyDuplicate(int[]nums,intk){intleft=-1;for(inti=0;i<nums......
  • Divide by Zero 2021 and Codeforces Round #714 C
    C.AddOne显然对于每一位单独分析我们经过一次进位只能变成10这样该怎么做呢我们显然可以dp设dp[i][j]表示i(0-9)经过j次变换有几位显然我们初始化i+j<10就是1elsed......
  • 20221304获奖感言和学习心得
    20221304获奖感言和学习心得获奖感言非常荣幸得到了娄老师的认可,获得了这份丰厚的奖品。在进入大学之前,我没有学过编程。一开学的时候确实有点不适应这样快的教学节奏,但......
  • 归档 221018 | 做题记录
    K.Differencehttps://loj.ac/p/2161好耶我会打\(n^3\)!这说明这道题\(n\)一定等于\(10^3\)!我超,是\(10^6\)????寄,,,,,枚举出现次数最多的字符(假设为\(x\))和出现次数最少......