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)首先这 ...
随机推荐
- maven项目导入war包
导入war包,使用war包中的类和静态资源(css,js,包含jsp等) A项目是被导入的war工程,B项目是需要A项目的一个工程. 在<build>中 <resources> ...
- poll & select
//todo /* * copied from http://devarea.com/linux-io-multiplexing-select-vs-poll-vs-epoll/#.W1GZ0vkzZ ...
- Java内置包装类
Java内置包装类有Object.Integer.Float.Double.Number.Charcter.Boolean.Byte.System. Number,是抽象类,也是超类(父类).Numb ...
- python学习第2天
03 pycharm使用04 格式化输出05 while循环 why: 吃饭睡觉上课, 地球绕着太阳公转,单曲循环,列表循环. what: while how: while 条件: 循环体 where ...
- laravel sql复杂语句,原生写法----连表分组
### 使用了临时表.又分组又连表的感觉好难写,使用拉 ravel 但是现在越来也相信,没解决一个新的难题,自己又进步了一点点 ### 原生的sql: select user_code, realna ...
- 【原创】大数据基础之Hive(5)hive on spark
hive 2.3.4 on spark 2.4.0 Hive on Spark provides Hive with the ability to utilize Apache Spark as it ...
- Confluence 6 MySQL 测试你的数据库连接
在你的数据库设置界面,有一个 测试连接(Test connection)按钮可以检查: Confluence 可以连接你的数据库服务器 数据库字符集,隔离级别和存储引擎是正确的 你的数据库用户有正确的 ...
- 弹框勾选datatable中的数据,点击保存后添加到另一个表中,同一个页面
需求描述:做编辑的时候,点击添加按钮,弹出数据表table2,勾选弹出框中的数据,点击保存后能够添加到table1中,并且已经被添加到table1中的数据,在弹出框中显示已选,checkbox隐藏:t ...
- SQLAchemy基础知识
一.什么是SQLAchemy? SQLAlchemy是Python编程语言下的一款ORM框架,该框架建立在数据库API之上,使用关系对象映射进行数据库操作,简言之便是:将对象转换成SQL,然后使用数据 ...
- web.xml中的ContextLoaderListener和DispatcherServlet区别
ContextLoaderListener和DispatcherServlet都会在Web容器启动的时候加载一下bean配置. 区别在于: DispatcherServlet一般会加载MVC相关的be ...