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, ...
随机推荐
- Luogu4916 魔力环 莫比乌斯反演、组合、生成函数
传送门 先不考虑循环同构的限制,那么对于一个满足条件的序列,如果它的循环节长度为\(d\),那么与它同构的环在答案中就会贡献\(d\)次. 所以如果设\(f_i\)表示循环节长度恰好为\(i\)的满足 ...
- C# 设置最顶层窗口。TopMostWindow
code: namespace LOLMM { /// <summary> /// Interaction logic for MainWindow.xaml /// </summa ...
- 腾讯AlloyTeam正式发布omi-cli脚手架 - 创建网站无需任何配置
omi-cli omi-cli omi-cli命令 omi框架 用户指南 文件目录 npm 脚本 npm start npm run dist 代码分割 兼容 IE8 插入 CSS 插入组件局部 CS ...
- case when then的用法-leetcode交换工资
case具有两种格式:简单case函数和case搜索函数. --简单case函数 case sex when ' then '男' when ' then '女’ else '其他' end --ca ...
- scrapy之五大核心组件
scrapy之五大核心组件 scrapy一共有五大核心组件,分别为引擎.下载器.调度器.spider(爬虫文件).管道. 爬虫文件的作用: a. 解析数据 b. 发请求 调度器: a. 队列 队列是一 ...
- JS_左边栏菜单
需求: 要求实现左边栏菜单点击一下就弹开,其他的隐藏.再点击一下就隐藏. 最多只能有一个菜单的详细内容会显示出来. 三个菜单实现联动效果. 代码如下: 1 <!DOCTYPE html> ...
- gin框架学习手册
前言 gin框架是go语言的一个框架,框架的github地址是:https://github.com/gin-gonic/gin 转载本文,请标注原文地址:https://www.cnblogs.co ...
- Prometheus & SoundCloud
Prometheus 系统监控方案 一 - Vovolie - 博客园https://www.cnblogs.com/vovlie/p/Prometheus_CONCEPTS.html Prometh ...
- react双组件传值和传参
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Window.scrollTo()
摘要 滚动到文档中的某个坐标. 语法 window.scrollTo(x-coord,y-coord ) window.scrollTo(options) 参数 x-coord 是文档中的横轴坐标. ...