Sereja and Sets

我们先考虑对于一堆线段我们怎么求最大的不相交的线段数量。

我们先按 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的更多相关文章

  1. CodeForces 425E Sereja and Sets

    意甲冠军: 集S它包括了很多间隔[l,r]  和1<=l<=r<=n  f(S)个不相交的区间  问给出n和f(S)  有几种可能的S集合 思路: dp好题  至于为啥是dp-  我 ...

  2. CodeForces - 425E Sereja and Sets 题解

    题目大意: 我们有一个集合 S,其中包含了 m 个不完全相同的区间[l1,r1],[l2,r2]…[lm,rm] (1≤li≤ri≤n,li,ri 都为整数). 定义 f(S)=k,表示集合 S 中能 ...

  3. Codeforces.314E.Sereja and Squares(DP)

    题目链接 http://www.cnblogs.com/TheRoadToTheGold/p/8443668.html \(Description\) 给你一个擦去了部分左括号和全部右括号的括号序列, ...

  4. [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆)

    [BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权 ...

  5. codeforces 425C Sereja and Two Sequences(DP)

    题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...

  6. CodeForces - 314C Sereja and Subsequences (树状数组+dp)

    Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...

  7. 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 ...

  8. 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  ...

  9. codeforces 486 D. Valid Sets(树形dp)

    题目链接:http://codeforces.com/contest/486/problem/D 题意:给出n个点,还有n-1条边的信息,问这些点共能构成几棵满足要求的树,构成树的条件是. 1)首先这 ...

随机推荐

  1. 生产环境elasticsearch5.0报错IllegalArgumentException: number of documents in the index cannot exceed 2147483519的处理

    最近几天的push:user:req数据写不到集群,报错如下: [--13T09::,][DEBUG][o.e.a.b.TransportShardBulkAction] [yunva_etl_es8 ...

  2. 1.ROS启动小乌龟

        启动turtlesim 在三个不同的终端中分别执行如下三个指令 roscore rosrun turtlesim turtlesim_node rosrun turtlesim turtle_ ...

  3. Android App签名打包

    Andriod应用程序如果要在手机或模拟器上安装,必须要有签名!  1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序 ...

  4. CSS入门(二)

    一.组合选择器 每个选择器位可以是任意基础选择器或选择器组合 1.群组选择器 可以一次性控制多个选择器 选择器之间用逗号(,)隔开 div,.d1,#div{ color:red; } 2.子代(后代 ...

  5. Jenkins五 配置tomcat

    一:jdk安装 查看系统自带jdk版本并卸载 [root@localhost conf]# rpm -qa|grep jdkjdk1.8-1.8.0_201-fcs.x86_64 移除: yum re ...

  6. Mac配置Jdk 安装及系统环境配置

    注:本文来于<  Mac配置Java开发环境    > 1. 下载JDK 从下面链接选择合适版本的安装包进行下载...笔者下载的是jdk-9.0.1 链接:http://www.oracl ...

  7. 探索一个NSObject对象占用多少内存?

    1 下面写代码测试探索NSObject的本质 Objective-C代码,底层实现其实都是C\C++代码 #import <Foundation/Foundation.h> int mai ...

  8. Swift DispatchQueue

    延迟2s执行 DispatchQueue.main.asyncAfter(deadline: DispatchTime.now()+2)

  9. usrp使用

    首先打开linux 输入uhd_find_divice gqrx

  10. SpringMVC类型转换,验证

    点击上一章-SpringMVC视图及REST风格 Spring mvc 数据绑定流程: SpringMvc将ServletRequest对象及目标方法的形参实例传给WebDataBinderFacto ...