CodeForces 431C k-Tree(dp)
来源:互联网 发布:抗战网络电影 编辑:程序博客网 时间:2024/05/20 05:54
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
- each vertex has exactly k children;
- each edge has some weight;
- if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
3 3 2
3
3 3 3
1
4 3 2
6
4 5 2
7
题意:给出K-Tree定义,每个结点都有恰好K个孩子,这棵树无限增长。每个节点到它K个孩子的K条边的权重刚好是1,2,3...,K。
现在问有多少条路径,使得从根节点出发到达某个结点,经过的边权重之和恰好为n,并且经过的边至少有一条权重不小于d。
dp[i][0]:表示权值和为i中不包含权值>=d的边。dp[i][j]:表示权值和为i中包含权值>=d的边。
dp[i][0]+=dp[i-j][0] (j<d)
dp[i][1]+=dp[i-j][0] (j>=d)
dp[i][1]+=dp[i-j][1];
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;long long dp[222][2];#define MOD 1000000007int main(){ int n,k,d; while (scanf("%d%d%d",&n,&k,&d)!=EOF) { memset(dp, 0, sizeof(dp)); dp[0][0]=1; for (int i=0; i<=n; i++) { for (int j=1; j<=k; j++) { if(i-j>=0) { if(j<d) { dp[i][0]+=dp[i-j][0]; } else { dp[i][1]+=dp[i-j][0]; } dp[i][1]+=dp[i-j][1]; dp[i][0]%=MOD; dp[i][1]%=MOD; } } } printf("%lld\n",dp[n][1]); } return 0;}
- 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 Round247 C k-tree DP
- CodeForces 431C K-Tree
- CodeForces 431C k-Tree
- Codeforces Round #247(Div. 2) C. k-Tree DP
- Codeforces 431C k-Tree 题解
- Codeforces #247 (Div. 2) C. k-Tree
- codeforces 431C DP
- 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
- wpf——datagrid中如何获取DataGridTextColumn等某行某列的值
- jquery调用自定义函数
- 在java中如何将String类型转换成java.sql.Date类型
- LVS基本介绍
- findViewById返回null
- CodeForces 431C k-Tree(dp)
- 哈希表算法
- redhat更改系统时间
- 如何管理多个dialog弹出
- SSO 原理浅谈
- Keil C51内存
- 前端构建工具gulpjs的使用介绍及技巧
- 黑马程序员_Java基础_IO(2)
- 2015年大一下第8周项目3-类族的设计