当前位置:网站首页>codeforces k-Tree (dp still won't work)
codeforces k-Tree (dp still won't work)
2022-08-02 17:05:00 【Ask for a guide】
题目
题意: 给定一棵树,每个节点恰好有k个儿子,The corresponding edge is exactly 1-k. Find out how many options there are,The weights on the satisfying path are exactly n,And at least one edge satisfies the edge weight>=d.
思路: It is actually lineardp,Each level can only be selected1-k.好久没dp就d不出来了,可以先dp一遍1-k都能用的,再dpCan only be used once1-(d-1)的,Subtraction is what satisfies the meaning of the question.f[0][i][j]: Use all sides,从前ilayer selected,Boundary right is exactly j的方案数.Just enumerate how many weights the current layer uses,can be delivered.f[0][i][j] = f[0][i-1][j-1…k]
Only depends on the previous layer,所以可以把iThis dimension is compressed.f[0][j] = f[0][j-1…k]
时间复杂度: O(n* n * k)或O(n*k)
代码:
#include<bits/stdc++.h>
using namespace std;
const int N = 102;
const int mod = 1e9+7;
int n,m,k,T;
int f[2][N]; //0:所有边,1:小于d的边,f[j]:权值为j的方案数
void solve()
{
cin>>n>>k>>m;
f[0][0] = 1;
for(int j=1;j<=n;++j) //权值
{
for(int t=1;t<=k;++t) //Where does the enum move from
{
if(j-t<0) break;
f[0][j] = (f[0][j] + f[0][j-t]) % mod;
}
}
k = m-1;
f[1][0] = 1;
for(int j=1;j<=n;++j) //权值
{
for(int t=1;t<=k;++t) //Where does the enum move from
{
if(j-t<0) break;
f[1][j] = (f[1][j] + f[1][j-t]) % mod;
}
}
long long ans = 0;
ans = (ans + f[0][n]) % mod;
ans = (ans - f[1][n]) % mod;
ans = (ans + mod) % mod;
cout<<ans;
}
signed main(void)
{
solve();
return 0;
}
边栏推荐
- 解决(An error happened during template parsing (template: “class path resource [templates/...]
- Redis最新6.27安装配置笔记及安装和常用命令快速上手复习指南
- 【QMT】给QMT量化交易软件安装和调用第三方库(举例通达信pytdx,MyTT,含代码)
- 初识art-template模板引擎
- 基于mobileNet实现狗的品种分类(迁移学习)
- 已解决ModuleNotFoundError: No module named‘ pip‘(重新安装pip的两种方式)
- DOM - page rendering process
- setTimeout与setInterval的区别
- 【无标题】
- 【数据知多少】一文学懂通过Tushare、AKshare、baostock、Ashare、Pytdx获取股票行情数据(含代码)
猜你喜欢
随机推荐
lammps学习(一)单晶硅纳米磨削
mysql 索引使用与优化
2022-07-13 第五小组 瞒春 学习笔记
第六章-6.1-堆-6.2-维护堆的性质-6.3-建堆
XML技术
mysql 自动添加创建时间、更新时间
PAT甲级 1137 期终成绩
一文让你快速写上扫雷游戏!童年的经典游戏,发给你的小女友让你装一波!!
nodemon : 无法加载文件 D:\Program Files\nodejs\node_global\nodemon.ps1
2022-07-16 第五小组 瞒春 学习笔记
2022年安全员-A证考试试题及模拟考试
已解决ModuleNotFoundError: No module named‘ pip‘(重新安装pip的两种方式)
太香了!阿里Redis速成笔记,从头到尾全是精华!
【Untitled】
PAT Class A 1145 Hash - Average Lookup Time
为什么四个字节的float表示的范围比八个字节的long表示的范围要广
延时函数-定时器
2022-07-25 第六小组 瞒春 学习笔记
JSP技术
为什么四个字节的float表示的范围比八个字节的long要广?









