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)首先这 ...
随机推荐
- web@h,c小总结
问题0:元素内联元素,行内元素,行内块元素. 内联: 宽高M,P都有效 行内元素:无宽高,内容撑开,M,P左右有效 行内块元素:可设宽高,内容撑开,M,P都有 ...
- percona mysql5.7关闭审计功能方法
数据库的审计日志占用大量空间,当时是为了测试审计功能开启的,现在需要关闭 # /data/mysql_data]# du -sh * 124G audit.log # 查询审计相关参数 mysql&g ...
- docker拉取镜像报错:net/http: TLS handshake timeout.
docker拉取镜像报错:net/http: TLS handshake timeout. 启动一个后台的busybox容器 [yunva@node1 network-scripts]$ docker ...
- 通过flask实现web页面简单的增删改查
通过flask实现web页面简单的增删改查 # 1.后台程序falsk_web01.py #coding:utf-8 from flask import Flask,render_template,r ...
- OpenSIPS 1.11.1安装记录
说明:操作系统Centos 6.5 64位 安装步骤: 1.安装依赖包 : yum -y install gcc make gdb wget yum -y install flex bison nc ...
- springcloud-3:required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
在写客户端程序的时候,总是报'com.netflix.discovery.DiscoveryClient' that could not be found. 原因在于导入了错误的类:com.netfl ...
- HTTP协议详解(一)
1 http协议介绍 1.1 简单介绍 HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consort ...
- [C]控制外部变量访问权限的extern和static关键字
一.extern 概述 编译器是由上至下编译源文件的,当遇到一些函数引用外部全局变量,而这个变量被定义在该函数声明主体的下方,又或者引用自其它的编译单元,这个情况就需要extern来向编译器表明此变量 ...
- iOS 去除高德地图下方的 logo 图标
[self.mapView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, ...
- SQL Server 函数之日期格式化函数
SQL Server 函数之日期格式化函数 高文龙关注0人评论612人阅读2017-09-23 13:47:07 SQL Server 函数之日期格式化函数 对于一些经常写SQL Server执行语句 ...