Codeforces 431C k-Tree 题解
来源:互联网 发布:富豪 面相 知乎 编辑:程序博客网 时间:2024/05/20 07:54
题意
一颗无穷的满k叉树,每一个节点与它的子节点相连的边的权值分别为1,2,…,k,问有多少条从根出发不重复经过边的路径满足经过的边权值之和为n而且至少经过一条权值不小于d的边
思路
dp,先不考虑第二个限制条件,那么数量就是dp[n][k]=∑min(n,k)i=1dp[n−i][k] ,再考虑第二个限制条件,我们发现正着考虑比较复杂,就从反面考虑,找到边全都小于d的路径数量就好了,那这个就是dp[n][d−1] ,所以两个数减一下就好了,注意取模
代码
#include <cstdio>#define mod 1000000007int dp[101][101];int main(){ int n,k,d; for(int i=1;i<=100;i++) dp[0][i]=1; for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) for(int k=1;k<=j;k++) { if(i-k>=0) dp[i][j]=(dp[i][j]+dp[i-k][j])%mod; else break; } scanf("%d%d%d",&n,&k,&d); printf("%d\n",(dp[n][k]-dp[n][d-1]+mod)%mod); return 0;}
0 0
- Codeforces 431C k-Tree 题解
- CodeForces 431C K-Tree
- CodeForces 431C k-Tree
- CodeForces 431C k-Tree(dp)
- codeforces-431C-k-Tree【dp】
- Codeforces 431C k-Tree (基础dp)
- Codeforces 431C k-Tree【dp】
- Codeforces 431C —— k-Tree(DP)
- Codeforces 431C k-tree DP(拆分数)
- Codeforces 431C —— k-Tree(DP)
- Codeforces 383C Propagating tree 题解&代码
- Codeforces Round247 C k-tree DP
- Codeforces #247 (Div. 2) C. k-Tree
- 【codeforces 764C】Timofey and a tree 题解
- Codefoces 431 C. k-Tree
- CF 431C k-Tree
- Codeforces Round #247 (Div. 2) C. k-Tree
- Codeforces Round #247 (Div. 2) C.K-Tree
- Git 分支
- [leetcode: Python]205. Isomorphic Strings
- DBImage 使用 Jpeg 图片(VCL)
- so.walk()简单实现,
- 依靠自学,争取帮助
- Codeforces 431C k-Tree 题解
- Codeigniter整合媒体解析类getid3
- IOS KVC 32位和64位的坑
- Linux之——bash: warning: setlocale: LC_CTYPE: cannot change locale (EN_US.UTF-8)
- hdoj 2037 今年暑假不AC
- java 连接 Mysql 的连接信息
- I/O字节流
- 设计模式之策略模式
- 线索化二叉树的创建及遍历