Codeforces 425E Sereja and Sets dp
我们先考虑对于一堆线段我们怎么求最大的不相交的线段数量。
我们先按 r 排序, 然后能选就选。
所以我们能想到我们用$dp[ i ][ j ]$表示已经选了 i 个线段, 最后一个被选的线段的右端点是 j 的方案数。
对于dp[ i ][ j ] -> dp[ i + 1 ][ k ], 所有能满足左端点 > j 右端点为 k 的方案数为1 << (k - j)种, 其他可以随意
放上取的方案数为1 << ( ( n - z ) * ( z - j ) )种, 所以可以得到
dp[ i + 1 ][ z ] += dp[ i ][ j ] * pow2[ (n - z) * (z - j) ] % mod * (pow2[ z - j ] - 1)
#include<bits/stdc++.h>
#define LL long long
#define LD long double
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); template<class T, class S> inline void add(T& a, S b) {
a += b; if(a >= mod) a -= mod;
}
template<class T, class S> inline void sub(T& a, S b) {
a -= b; if(a < ) a += mod;
}
template<class T, class S> inline bool chkmax(T& a, S b) {
return a < b ? a = b, true : false;
}
template<class T, class S> inline bool chkmin(T& a, S b) {
return a > b ? a = b, true : false;
} int n, k;
int dp[N][N];
int pow2[N * N]; int main() {
for(int i = pow2[] = ; i < N * N; i++)
pow2[i] = 1LL * pow2[i - ] * % mod;
scanf("%d%d", &n, &k);
dp[][] = ;
for(int i = ; i < k; i++) {
for(int j = ; j <= n; j++) {
if(!dp[i][j]) continue;
for(int z = j + ; z <= n; z++) {
add(dp[i + ][z], 1LL * dp[i][j] * pow2[(n - z) * (z - j)] % mod * (pow2[z - j] - ) % mod);
}
}
}
int ans = ;
for(int i = ; i <= n; i++)
add(ans, dp[k][i]);
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 425E Sereja and Sets dp的更多相关文章
- CodeForces 425E Sereja and Sets
		意甲冠军: 集S它包括了很多间隔[l,r] 和1<=l<=r<=n f(S)个不相交的区间 问给出n和f(S) 有几种可能的S集合 思路: dp好题 至于为啥是dp- 我 ... 
- CodeForces - 425E Sereja and Sets 题解
		题目大意: 我们有一个集合 S,其中包含了 m 个不完全相同的区间[l1,r1],[l2,r2]…[lm,rm] (1≤li≤ri≤n,li,ri 都为整数). 定义 f(S)=k,表示集合 S 中能 ... 
- Codeforces.314E.Sereja and Squares(DP)
		题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ... 
- [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)
		[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ... 
- codeforces 425C Sereja and Two Sequences(DP)
		题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ... 
- CodeForces - 314C  Sereja and Subsequences (树状数组+dp)
		Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ... 
- Codeforces Round #277 (Div. 2) D. Valid Sets (DP DFS 思维)
		D. Valid Sets time limit per test 1 second memory limit per test 256 megabytes input standard input ... 
- Codeforces Round #277 (Div. 2) D. Valid Sets DP
		D. Valid Sets As you know, an undirected connected graph with n nodes and n - 1 edges is called a ... 
- codeforces 486 D. Valid Sets(树形dp)
		题目链接:http://codeforces.com/contest/486/problem/D 题意:给出n个点,还有n-1条边的信息,问这些点共能构成几棵满足要求的树,构成树的条件是. 1)首先这 ... 
随机推荐
- luci 中require函数包含的路径
			在 lua 脚本中常用的包含某个文件就是 require 函数. 例如: #!/usr/bin/lua // 表明使用的是lua脚本,像shell脚本一样 lo ... 
- HBase Snapshot简介
			一.简介 HBase 从0.95开始引入了Snapshot,可以对table进行Snapshot,也可以Restore到Snapshot.Snapshot可以在线做,也可以离线做.Snapshot的实 ... 
- eclipse的工程中如何查找字符串
			ctrl + h 后弹出 tab选项, 你选择 file search 然后在下面输入要查找的字符串 workset 那里选择你要查找的项目 默认是全部项目进行查找 
- Golang的单引号、双引号与反引号
			Go语言的字符串类型string在本质上就与其他语言的字符串类型不同: Java的String.C++的std::string以及Python3的str类型都只是定宽字符序列 Go语言的字符串是一个用 ... 
- swift 实践- 13 -- UIStepper
			import UIKit class ViewController: UIViewController { var stepper: UIStepper! var label: UILabel! ov ... 
- Windows服务启动进程----Cjwdev.WindowsApi.dll
			windows服务下无法启动外部程序 做一个windows服务监听服务,涉及到windows服务启动外部程序的一个过程,但是调试测试发现,无法简单的用process.start()这种方法, 原因是在 ... 
- Confluence 6 Windows 中以服务方式自动重启为服务手动安装 Confluence 分发包
			在 Windows: 打开一个命令输入框,然后修改目录到 <CONFLUENCE-INSTALL>/bin 目录中.你需要以管理员权限运行这个命令行输入框(Run as administr ... 
- Confluence 6 管理应用服务器内存设置
			应用服务器中的最小和最大 JVM Heap 空间配置将会影响系统的性能.Confluence 管理员可能希望对默认的配置进行修改,基于你系统的负载不同配置情况也会有所不同,请参考页面 Server H ... 
- Confluence 6 连接到外部用户目录服务器的问题分析
			在有关外部目录服务器配置页面中有一个测试配置(Test Settings)按钮.这个功能将会帮助你分析你的用户管理在 Active Directory 和其他 LDAP 服务器中出现的问题. 希望对你 ... 
- Remove Duplicates from Sorted ListII
			给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4->4->5 输出: 1-&g ... 
