codeforces431C
k-Tree
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 kedges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: "How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?".
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).
Input
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).
Output
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Examples
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。
sol:dp应该看得出来,状态也很好构建dp[i][j][0,1]表示到第i层和为j是否有不小于d的边,因为n,k太小,毫无思考的n3dp直接上
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int Mod=,N=;
int n,K,D;
int dp[N][N][];
int main()
{
int i,j,k;
R(n); R(K); R(D);
dp[][][]=;
for(i=;i<=n;i++)
{
for(j=i-;j<n;j++)
{
for(k=;j+k<=n&&k<=K;k++)
{
dp[i][j+k][]+=1ll*dp[i-][j][]%Mod;
dp[i][j+k][]-=(dp[i][j+k][]>=Mod)?Mod:;
if(k>=D)
{
dp[i][j+k][]+=1ll*dp[i-][j][]%Mod;
dp[i][j+k][]-=(dp[i][j+k][]>=Mod)?Mod:;
}
else
{
dp[i][j+k][]+=1ll*dp[i-][j][]%Mod;
dp[i][j+k][]-=(dp[i][j+k][]>=Mod)?Mod:;
}
}
}
}
int ans=;
for(i=;i<=n;i++)
{
ans+=dp[i][n][];
ans-=(ans>=Mod)?Mod:;
}
Wl(ans);
return ;
}
/*
input
3 3 2
output
3 input
3 3 3
output
1 input
4 3 2
output
6 input
4 5 2
output
7
*/
codeforces431C的更多相关文章
- 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)
题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...
随机推荐
- 圆角矩形shader
在游戏中,有时需要对一张矩形图片进行切割,绘制成圆角矩形. circelrect.vert attribute vec4 a_position; attribute vec4 a_normal; at ...
- JS判断当前设备是 PC IOS Andriod
JS判断当前设备是 PC IOS Andriod <script > window.onload = function(){ var isPc = IsPC(); var isAndroi ...
- Python全栈开发之路 【第五篇】:Python基础之函数进阶(装饰器、生成器&迭代器)
本节内容 一.名称空间 又名name space,就是存放名字的地方.举例说明,若变量x=1,1存放于内存中,那名字x存放在哪里呢?名称空间正是存放名字x与1绑定关系的地方. 名称空间共3种,分别如下 ...
- vue开发中regeneratorRuntime is not defined
我的项目是用vue提供的vue-cil脚手架生成的项目,但是当我在项目中使用async/await,编译代码的的时候报了regeneratorRuntime is not defined的错,我查过资 ...
- An error occurred while updating the entries. See the inner exception for details.
EF插入或更新数据时出现错误提示:An error occurred while updating the entries. See the inner exception for details.的 ...
- mysql触发器,视图,游标
什么事触发器: 触发器是一中特殊的存储过程,主要是通过事件来触发而被执行的.它可以强化约束,来维护数据的完整性和一致性,可以跟踪数据库内的操作从而不允许未经许可的更新和变化.可以联级运算.如,某表上的 ...
- Eclipse中Git的使用以及IDEA中Git的使用
一.Eclipse中Git解决冲突步骤: 1.进行文件对比,将所有的文件添加到序列. 2.commit文件到本地仓库. 3.pull将远程仓库的代码更新到本地,若有冲突则会所有的文件显示冲突状态(真正 ...
- 每周分享之cookie详解
本章从JS方向讲解cookie的使用.(实质上后端代码也是差不多用法,无非读取和设置两块) 基本用法:document.cookie="username=pengpeng"; 修改 ...
- 模拟银行ATM系统(基础版)
Account类 package ATM; public class Account {//定义Account类 private String accountID;//用于存储学生的用户账号(由八位数 ...
- Spring LocalVariableTableParameterNameDiscoverer获取方法的参数名
Spring LocalVariableTableParameterNameDiscoverer获取方法的参数名 问题:Java.lang.reflect 包中提供了很多方法,获取所有的方法,获取所有 ...