当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
2022-02-14 第五小组 瞒春 学习笔记
EL 表达式 & JSTL 标签库
页面返回顶部和固定导航栏js基础案例
scroll、offset、client事件的用法及区别
一文让你快速写上扫雷游戏!童年的经典游戏,发给你的小女友让你装一波!!
Selenium元素定位方法总结
【 Leetcode string, the string transform/hexadecimal conversion 】 HJ1. The length of the string last word HJ2. Calculation of a certain number of characters appear HJ30. String merging processing
如何使用Swiper外部插件写一个轮播图
事件对象,事件流(事件冒泡和事件捕获)、事件委托、L0和L2注册等相关概念及用法
加载事件的用法
C语言的基本程序结构详细讲解
The difference and connection between dist, pdist and pdist2 in MATLAB
【js手风琴效果案例】
【无标题】
我的第一篇博客
散列表简述
Mechanical keyboard failure
一文让你快速手写C语言-三子棋游戏
两分钟录音就可秒变语言通!火山语音音色复刻技术如何修炼而成?
基于ip的证书