当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
lambda表达式、Stream接口及Optional类
双亲委派机制
告别手摇织布机的AI时代
“绿色低碳+数字孪生“双轮驱动,解码油气管道站升级难点 | 图扑软件
类加载过程
servlet交互过程图详解,servlet的常见问题,创建web项目(一)
C语言中国象棋源码以及图片
this beta version of Typora is expired, please download and install a newer version.Typora的保姆级最新解决方法
XML技术
加载事件的用法
我的第一篇博客
如何查看微信小程序服务器域名并且修改
MySQL 自增主键
【无标题】
DOM - Event Mechanism and Event Chain
scroll、offset、client事件的用法及区别
学习编程的目标
2022-7-12 第五组 瞒春 学习报告
2022年安全员-A证考试试题及模拟考试
第三章-函数的增长-3.1-渐近记号









