Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) F - Uniformly Branched Trees 无根树->有根树+dp
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = 1e3 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f; LL dp[N][][N], inv[N], f[N], finv[N], g[N][];
int n, d, mod; void init() {
inv[] = f[] = finv[] = ;
for(int i = ; i < N; i++) inv[i] = (mod-mod/i)*inv[mod%i]%mod;
for(int i = ; i < N; i++) f[i] = f[i-]*i%mod;
for(int i = ; i < N; i++) finv[i] = finv[i-]*inv[i]%mod;
} int main() {
scanf("%d%d%d", &n, &d, &mod);
init();
for(int i = ; i <= n; i++) dp[][][i] = ;
for(int i = ; i <= d; i++) g[][i] = ;
for(int i = ; i <= n; i++) {
for(int j = ; j <= d; j++) {
for(int k = ; k < i; k++) {
for(int l = ; l <= j && l*k <= i; l++) {
dp[i][j][k] = (dp[i][j][k] + 1ll*dp[i-l*k][j-l][k-]*g[k][l])%mod;
}
}
for(int k = ; k <= n; k++) dp[i][j][k] = (dp[i][j][k]+dp[i][j][k-])%mod;
}
g[i][] = dp[i][d-][n];
for(int j = ; j <= d; j++)
g[i][j] = g[i][j-]*(dp[i][d-][n]+j-)%mod*inv[j]%mod;
}
LL ans = ;
if(n <= ) ans = ;
else ans = dp[n][d][n/];
if(n > && !(n&)) {
ans = (ans + mod - dp[n/][d-][n/] * (dp[n/][d-][n/]-) / % mod) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) F - Uniformly Branched Trees 无根树->有根树+dp的更多相关文章
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)
题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...
随机推荐
- protobuf手册
1. c++快速上手 https://developers.google.com/protocol-buffers/docs/cpptutorial 2. c++使用手册 https://develo ...
- lightoj 1148 Mad Counting(数学水题)
lightoj 1148 Mad Counting 链接:http://lightoj.com/volume_showproblem.php?problem=1148 题意:民意调查,每一名公民都有盟 ...
- 5.UiScrollable API 详细介绍
Tip: 1.扫动过程中如果界面停留在滚动条的中间部分会先回到起点再进行滚动 2.扫动过程中设置的步长长短决定划过内容的多少,步长越长滑过的内容就越少:步长越短划过的内容就越长 一.UiScrolla ...
- (转)IO复用,AIO,BIO,NIO,同步,异步,阻塞和非阻塞 区别
本文来自:https://www.cnblogs.com/aspirant/p/6877350.html?utm_source=itdadao&utm_medium=referral,非常感谢 ...
- sqlserver 2008备份与还原
一.SQL数据库的备份: 1.依次打开 开始菜单 → 程序 → Microsoft SQL Server 2008 → SQL Server Management Studio → 数据库:Dside ...
- (2.1)windows下Nutch1.7的安装
酒店评论情感分析系统(二)——Nutch安装 一.需求部分 Nutch是Java开发的所以需要下载Java JDK. 下载地址http://java.sun.com/javase/downloads/ ...
- canvas h5制作写字板
<!DOCTYPE html><html><head> <meta charset="utf-8"> <script type ...
- 从urllib和urllib2基础到一个简单抓取网页图片的小爬虫
urllib最常用的两大功能(个人理解urllib用于辅助urllib2) 1.urllib.urlopen() 2. urllib.urlencode() #适当的编码,可用于后面的post提交 ...
- NB二人组(一)----堆排序
堆排序前传--树与二叉树简介 特殊且常用的树--二叉树 两种特殊的二叉树 二叉树的存储方式 二叉树小结 堆排序 堆这个玩意....... 堆排序过程: 构造堆: 堆排序的算法程序(程序需配合着下图理 ...
- python3学习笔记.1.初体验
最近工作烦得很 就想找点儿别的事情来做,于是想到了学学python. 因为是vs2017,所以就在里面安装了. 第一个程序肯定是Hello World了. 新建一个python应用程序 代码只有一行 ...