[CF431C]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 k k -tree.
A k k k -tree is an infinite rooted tree where:
- each vertex has exactly k k k children;
- each edge has some weight;
- if we look at the edges that goes from some vertex to its children (exactly k k k edges), then their weights will equal 1,2,3,...,k 1,2,3,...,k 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 n n (the sum of all weights of the edges in the path) are there, starting from the root of a k k k -tree and also containing at least one edge of weight at least d d d ?".Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 1000000007 1000000007 ( 109+7 10^{9}+7 109+7 ).
输入输出格式
输入格式:
A single line contains three space-separated integers: n n n , k k k and d d d ( 1<=n,k<=100; 1<=n,k<=100; 1<=n,k<=100; 1<=d<=k 1<=d<=k 1<=d<=k ).
输出格式:
Print a single integer — the answer to the problem modulo 1000000007 1000000007 1000000007 ( 109+7 10^{9}+7 109+7 ).
输入输出样例
4 5 2
7
简单的DP。
设f[i][j][0/1]为目前在深度为i,和为j,是否出现多大于等于d的边的方案数。
然后随便转移。
因为转移比较特色可以省掉第一维。
貌似网上还有别的方法。
f[i][j]表示和为i,出现的最大边权是j的方案数。
f[i+k][max(j,k)] += f[i][j]。
#include <bits/stdc++.h>
using namespace std;
#define reg register
#define mod 1000000007
int n, K, d;
int f[][][];
int ans; int main()
{
scanf("%d%d%d", &n, &K, &d);
f[][][] = ;
for (reg int i = ; i <= n ; i ++) //dep
{
for (reg int j = ; j <= n ; j ++) //tot val
{
for (reg int k = ; k <= K ; k ++) //the edge run
{
if (j - k < ) break;
if (k >= d) f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
else f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
f[i][j][] = (f[i][j][] + f[i-][j-k][]) % mod;
}
}
}
for (reg int i = ; i <= n ; i ++) ans = (ans + f[i][n][]) % mod;
cout << ans << endl;
return ;
}
[CF431C]k-Tree的更多相关文章
- E - Count on a tree 树上第K小
主席树的入门题目,这道题的题意其实就是说,给你一棵树,询问在两个节点之间的路径上的区间第K小 我们如何把树上问题转换为区间问题呢? 其实DFS就可以,我们按照DFS的顺序,对线段树进行建树,那么这个树 ...
- AOJ DSL_2_C Range Search (kD Tree)
Range Search (kD Tree) The range search problem consists of a set of attributed records S to determi ...
- HDU3333 Turing Tree(线段树)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=3333 Description After inventing Turing Tree, 3x ...
- Codeforces 343D Water Tree(DFS序 + 线段树)
题目大概说给一棵树,进行以下3个操作:把某结点为根的子树中各个结点值设为1.把某结点以及其各个祖先值设为0.询问某结点的值. 对于第一个操作就是经典的DFS序+线段树了.而对于第二个操作,考虑再维护一 ...
- Codeforces 620E New Year Tree(DFS序 + 线段树)
题目大概说给一棵树,树上结点都有颜色(1到60),进行下面两个操作:把某结点为根的子树染成某一颜色.询问某结点为根的子树有多少种颜色. 子树,显然DFS序,把子树结点映射到连续的区间.而注意到颜色60 ...
- POJ3321 Apple Tree(DFS序)
题目,是对一颗树,单点修改.子树查询.典型的dfs序入门题. DFS序可以将一颗树与子树们表示为一个连续的区间,然后用线段树来维护:感觉算是树链剖分的一种吧,和轻重链剖分不同的是这是对子树进行剖分的. ...
- poj3237 Tree
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...
- Size Balanced Tree(SBT) 模板
首先是从二叉搜索树开始,一棵二叉搜索树的定义是: 1.这是一棵二叉树: 2.令x为二叉树中某个结点上表示的值,那么其左子树上所有结点的值都要不大于x,其右子树上所有结点的值都要不小于x. 由二叉搜索树 ...
- [模板] K-D Tree
K-D Tree K-D Tree可以看作二叉搜索树的高维推广, 它的第 \(k\) 层以所有点的第 \(k\) 维作为关键字对点做出划分. 为了保证划分均匀, 可以以第 \(k\) 维排名在中间的节 ...
- HDU 2665.Kth number 区间第K小
Kth number Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- kubernetes集群部署高可用Postgresql的Stolon方案
目录 前言 ....前言 本文选用Stolon的方式搭建Postgresql高可用方案,主要为Harbor提供高可用数据库,Harbor搭建可查看kubernetes搭建Harbor无坑及Harbor ...
- 第五场周赛(字符串卡常个人Rank赛)——题解
本次题目因为比较简单,除了个别题目,其余题目我只写一个思路不再贴代码. 先是Div.2的题解 A题奇怪的优化,把递归函数改成2*fun(...)即可,其实看懂程序也不难,就是求a*2b: B题你会st ...
- 62 (OC)* leetCode 力扣 算法
1:两数之和 1:两层for循环 2:链表的方式 视频解析 2:两数相加 两数相加 3. 无重复字符的最长子串 给定一个字符串,请找出其中长度最长且不含有重复字符的子串,计算该子串长度 无重复字符的最 ...
- 使Flask的url支持正则表达式以及一个api小demo
from flask import Flask from flask import jsonify from flask import request from werkzeug.routing im ...
- 2018年蓝桥杯java b组第五题
标题:快速排序 以下代码可以从数组a[]中找出第k小的元素. 它使用了类似快速排序中的分治算法,期望时间复杂度是O(N)的. 请仔细阅读分析源码,填写划线部分缺失的内容. 我在使用(a, l, r, ...
- 今天第一次解决了程序在未装VS和XP下运行的问题
http://www.cnblogs.com/zero5/p/3162948.html 一位素不相识的朋友做的代码雨屏保程序 - 残雪孤侠 - 博客园 上面是我的BLOG 群共享里,有程序和代码 ...
- .net core 使用Rotativa创建PDF文档
一.下载Rotaiva 工具 = > NuGet包管理器 = > 管理解决方案的NuGet程序包 在打开的页面中搜索 Rotativa.AspNetCore 如下图: 选中红框的记 ...
- 我的mongoDb之旅(一)
开发环境 php版本:7.0.10 mongodb版本:1.5 开发框架:tp5 数据库工具:navicat12formongodb 可以参考的外部文件链接 tp5中mongodb的扩展说明:http ...
- 向net core 3.0进击——April.WebApi从2.2爬到3.0
目录 前言 升级之路 测试 小结 前言 在之前对Swagger的变化做了调整后,就开始想着要不把之前的工程升级得了,这样就还是个demo工程,来做各种测试(当然还是因为懒),这就有了今天这个比较折腾的 ...
- MongoDB 学习笔记之 replica set搭建
Replica set搭建: 修改mongodb.conf文件,指明replSet 登入客户端,指定副本集成员,进行初始化, 如果priority需要调整,使用reconfig()方法.Seconda ...