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, ...
随机推荐
- Java NIO2:NIO概述
一.概述 从JDK1.4开始,Java提供了一系列改进的输入/输出处理的新特性,被统称为NIO(即New I/O).新增了许多用于处理输入输出的类,这些类都被放在java.nio包及子包下,并且对原j ...
- linux内存源码分析 - 零散知识点
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 直接内存回收中的等待队列 内存回收详解见linux内存源码分析 - 内存回收(整体流程),在直接内存回收过程中, ...
- Python3 tkinter基础 Checkbutton variable 多选钮是否被选中
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 移动前端webApp开发点滴积累20140629
#移动前端webApp开发点滴积累20140629 ##关于input行内居中的问题 给input设定一个比较高的高度,在某些版本的移动设备上,文字不能垂直居中,即使设定了相同的行高也不行.(见图) ...
- Python全栈开发之路 【第十八篇】:Ajax技术
Ajax技术 Ajax = 异步 JavaScript 和 XML. Ajax 是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术. 1.jQuery的load()方法 jQuery loa ...
- Redux 入门教程(二):中间件与异步操作
上一篇文章,介绍了 Redux 的基本做法:用户发出 Action,Reducer 函数算出新的 State,View 重新渲染. 但是,一个关键问题没有解决:异步操作怎么办?Action 发出以后, ...
- H5 26-CSS三大特性之优先级
26-CSS三大特性之优先级 类>标签>通配符>继承>浏览器默认 --> 0 我是段落 <!DOCTYPE html> <html lang=" ...
- springboot 双数据源+aop动态切换
# springboot-double-dataspringboot-double-data 应用场景 项目需要同时连接两个不同的数据库A, B,并且它们都为主从架构,一台写库,多台读库. 多数据源 ...
- iOS蓝牙开发之iBeacon技术
iBeacon组成信息: 1 .UUID(universally unique identifier):一个128位的唯一标识一个或多个Beacon基站为特定类型或特定的组织. 2. Major:一个 ...
- nmon for Linux & Java
nmon for Linux | Main / HomePagehttp://nmon.sourceforge.net/pmwiki.php Java Nmon Analyser download | ...