Codeforces 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的更多相关文章
- Codeforces 343D Water Tree(DFS序 + 线段树)
题目大概说给一棵树,进行以下3个操作:把某结点为根的子树中各个结点值设为1.把某结点以及其各个祖先值设为0.询问某结点的值. 对于第一个操作就是经典的DFS序+线段树了.而对于第二个操作,考虑再维护一 ...
- Problem - D - Codeforces Fix a Tree
Problem - D - Codeforces Fix a Tree 看完第一名的代码,顿然醒悟... 我可以把所有单独的点全部当成线,那么只有线和环. 如果全是线的话,直接线的条数-1,便是操作 ...
- codeforces 570 D. Tree Requests 树状数组+dfs搜索序
链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds mem ...
- codeforces 375D:Tree and Queries
Description You have a rooted tree consisting of n vertices. Each vertex of the tree has some color. ...
- Codeforces 431C - k-Tree - [树形DP]
题目链接:https://codeforces.com/problemset/problem/431/C 题意: 定义一个 $k$ 树,即所有节点都有 $k$ 个儿子节点,相应的这 $k$ 条边的权重 ...
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- Codeforces 765 E. Tree Folding
题目链接:http://codeforces.com/problemset/problem/765/E $DFS子$树进行$DP$ 大概分以下几种情况: 1.为叶子,直接返回. 2.长度不同的路径长度 ...
- codeforces 1133E K Balanced Teams
题目链接:http://codeforces.com/contest/1133/problem/E 题目大意: 在n个人中找到k个队伍.每个队伍必须满足最大值减最小值不超过5.求满足条件k个队伍人数的 ...
- Codeforces 932.D Tree
D. Tree time limit per test 2 seconds memory limit per test 512 megabytes input standard input outpu ...
随机推荐
- 完整table
.table-bordered{ border:1px solid #cccccc; } .table { border-spacing: 0;/*设置或检索当表格边框独立时(即border-coll ...
- UVA10066
/* 最长公共子序列 */ #include <cstdio> #include <string.h> #include <iostream> const int ...
- linux测试带宽命令,Linux服务器网络带宽测试iperf
linux测试带宽命令,Linux服务器网络带宽测试iperf必须先运行iperf serveriperf -s -i 2客户端iperf -c 服务端IP地址 iperf原理解析 iperf工具可以 ...
- web前端----jQuery动画效果
动画效果 // 基本 show([s,[e],[fn]]) hide([s,[e],[fn]]) toggle([s],[e],[fn]) // 滑动 slideDown([s],[e],[fn]) ...
- Python中模块(Module)和包(Package)的区别
本文绝大部分内容转载至:廖雪峰官方网站 1. 模块(Module) 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函 ...
- bzoj1704 / P2882 [USACO07MAR]面对正确的方式Face The Right Way
P2882 [USACO07MAR]面对正确的方式Face The Right Way $n<=5000$?枚举翻转长度,顺序模拟就ok了 对于每次翻转,我们可以利用差分的思想,再搞搞前缀和. ...
- 03:requests与BeautifulSoup结合爬取网页数据应用
1.1 爬虫相关模块命令回顾 1.requests模块 1. pip install requests 2. response = requests.get('http://www.baidu.com ...
- android 实践项目四
android 实践项目四 本周主要是开发android baidumap实现公交的查询 1.权限的取得和对屏幕的支持 <uses-permission android:name="a ...
- C# MD5一句话加密
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5")
- Python3基础 print , 输出多个数据
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...