当前位置:网站首页>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;
}
边栏推荐
- 2021 Huawei Cup Mathematical Modeling Contest E question - Ultra-Wideband (UWB) precise positioning problem under signal interference
- idea使用jdbc对数据库进行增删改查,以及使用懒汉方式实现单例模式
- 集成电路实践----D触发器
- DOM - Event Mechanism and Event Chain
- 2022年低压电工考试试题及在线模拟考试
- 第三章-函数的增长-3.1-渐近记号
- 只出现一次的数字||| —— 哈希映射、异或位运算+分治思想
- 【Untitled】
- servlet交互过程图详解,servlet的常见问题,创建web项目(一)
- MySQL 视图(详解)
猜你喜欢
随机推荐
vite.config.ts introduces the `path` module Note!
vite.config.ts 引入 `path` 模块注意点!
2022年低压电工考试试题及在线模拟考试
Filter 过滤器
2022-07-20 第六小组 瞒春 学习笔记
如何正确且快速的清楚C盘!!释放C盘空间内存保姆级教程
如何查看微信小程序服务器域名并且修改
MySQL (2)
PAT Class A 1078 Hash
2022年安全员-A证考试试题及模拟考试
PAT甲级 1143 最低公共祖先
2022-07-18 第五小组 瞒春 学习笔记
单例模式(singleton pattern)
MATLAB file operations
【 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
马甲包接入过程记录
JS本地存储(附实例)
IPtables 和binlog
第五章-5.2-指示器随机变量
Application software code signing certificate








