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)首先这 ...
随机推荐
- Git系列①之仓库管理互联网托管平台github.com的使用
互联网项目托管平台github.com的使用 1.安装git客户端 # yum install -y git 配置git全局用户以及邮箱 [root@web01 ~]# git config --gl ...
- 转载:UML学习(二)-----类图(silent)
原文:http://www.cnblogs.com/huiy/p/8552607.html 1.什么是类图 类图(Class diagram)主要用于描述系统的结构化设计.类图也是最常用的UML图,用 ...
- ajax返回的欧洲字符(例如:法文)乱码
ajax返回值的乱码现象产生的相关代码如下: Java代码: JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(&quo ...
- python深浅拷贝与赋值
初学编程的小伙伴都会对于深浅拷贝的用法有些疑问,今天我们就结合python变量存储的特性从内存的角度来谈一谈赋值和深浅拷贝~~~ 预备知识一——python的变量及其存储 在详细的了解python中赋 ...
- tp5结合FormData实现ajax文件上传
或者使用: 下面使用jquery.form.js的表单插件来提交表单
- Android组件化demo实现以及遇坑分享
首先贴出demo的github地址:GitHub - TenzLiu/TenzModuleDemo: android组件化demo 作者:TenzLiu原文链接:https://www.jianshu ...
- canvas 保存bitmap到本地
File f = new File("/sdcard/DCIM/Camera/0.png"); FileOutputStream fos = null; try { fos = n ...
- NumPy:数组计算
一.MumPy:数组计算 1.NumPy是高性能科学计算和数据分析的基础包.它是pandas等其他各种工具的基础.2.NumPy的主要功能: ndarray,一个多维数组结构,高效且节省空间 无需循环 ...
- python网络爬虫笔记(九)
4.1.1 urllib2 和urllib是两个不一样的模块 urllib2最简单的就是使用urllie2.urlopen函数使用如下 urllib2.urlopen(url[,data[,timeo ...
- CentOS6.8安装MySQL5.7.20时报Curses library not found解决
报错如下: CMakeErroratcmake/readline.cmake:83(MESSAGE): Curseslibrarynotfound.Pleaseinstallappropriatepa ...