431C - k-Tree

思路:dp.

dp[i][j][s]

如果s为1,表示第i层长度为j且至少包含一段>=d的距离的路径数

如果s为0,表示第i层长度为j且不包含一段>=d的距离的路径数

状态转移看代码

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) const int MOD=1e9+;
const int N=;
ll dp[N][N][];
int main(){
ios::sync_with_stdio(false);
cin.tie();
int n,k,d;
cin>>n>>k>>d;
for(int i=;i<=k;i++)if(i>=d)dp[][i][]=;else dp[][i][]=;
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
for(int ii=;ii<=min(j,k);ii++){
if(ii>=d)dp[i][j][]=(dp[i][j][]+dp[i-][j-ii][]+dp[i-][j-ii][])%MOD;
else dp[i][j][]=(dp[i][j][]+dp[i-][j-ii][])%MOD,dp[i][j][]=(dp[i][j][]+dp[i-][j-ii][])%MOD;
}
//cout<<dp[i][j][1]<<' ';
}
//cout<<endl;
}
ll ans=;
for(int i=;i<=n;i++)ans=(ans+dp[i][n][])%MOD;
cout<<ans<<endl;
return ;
}

Codeforces 431C - k-Tree的更多相关文章

  1. Codeforces 343D Water Tree(DFS序 + 线段树)

    题目大概说给一棵树,进行以下3个操作:把某结点为根的子树中各个结点值设为1.把某结点以及其各个祖先值设为0.询问某结点的值. 对于第一个操作就是经典的DFS序+线段树了.而对于第二个操作,考虑再维护一 ...

  2. Problem - D - Codeforces Fix a Tree

    Problem - D - Codeforces  Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作 ...

  3. codeforces 570 D. Tree Requests 树状数组+dfs搜索序

    链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds mem ...

  4. codeforces 375D:Tree and Queries

    Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...

  5. Codeforces 431C - k-Tree - [树形DP]

    题目链接:https://codeforces.com/problemset/problem/431/C 题意: 定义一个 $k$ 树,即所有节点都有 $k$ 个儿子节点,相应的这 $k$ 条边的权重 ...

  6. Codeforces gym102152 K.Subarrays OR

    传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...

  7. Codeforces 765 E. Tree Folding

    题目链接:http://codeforces.com/problemset/problem/765/E $DFS子$树进行$DP$ 大概分以下几种情况: 1.为叶子,直接返回. 2.长度不同的路径长度 ...

  8. codeforces 1133E K Balanced Teams

    题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...

  9. Codeforces 932.D Tree

    D. Tree time limit per test 2 seconds memory limit per test 512 megabytes input standard input outpu ...

随机推荐

  1. #C++初学记录(ACM试题1)

    A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...

  2. cxf的使用

    java的一个rest路径包含五个部分 1.容器路径,如tomcat的文件包名,jetty的context等 2.web.xml -配置cxf或者sevlet等 3.cxf.xml 4.具体的实现类中 ...

  3. c#: using Microsoft.Office.Interop.Excel 异常

    解决方法: Project>Reference>右键Add Reference...>Choose Microsoft Excel 15.0 Object Library

  4. python-安装,设置环境变量(win10)

    python官网: https://www.python.org/ 选择需要的版本下载 下载后安装 我装的是默认位置C:\Python27 打开环境变量设置: 右键电脑--->属性----> ...

  5. 小K(wifi)插座剖解

    1.主控 AR9331 400MHZ MIPS 24k内核 2.flash:w9425G6JH-5 1352P 6316CF500ZY  RAM 32M

  6. Vue 父组件循环使用refs调用子组件方法出现undefined的问题

    Vue 父组件循环使用refs调用子组件方法出现undefined的问题 1. 背景 最近前端项目遇到一个问题,我在父组件中使用了两个相同的子组件child,分别设置ref为add和update.其中 ...

  7. Python3基础 __getattr__ 访问不存在的属性时,新增提示功能

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. 简谈高通Trustzone的实现【转】

    本文转载自:https://blog.csdn.net/hovan/article/details/42520879 从trust zone之我见知道,支持trustzone的芯片会跑在两个世界. 普 ...

  9. 我在linux中使用的vundle 和 vimrc配置

    set nocompatible filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc() Plugin 'gmarik/vundle' ...

  10. 打印图形|2014年蓝桥杯B组题解析第五题-fishers

    打印图形 小明在X星球的城堡中发现了如下图形和文字: rank=3 rank=5 rank = 6 小明开动脑筋,编写了如下的程序,实现该图形的打印. 答案:f(a, rank-1, row, col ...