2016弱校联盟十一专场10.2 Longest Increasing Subsequence
这个dp题很有学问,我也是照着标称写的
还需要学习
补: if(order[i] < order[i-1]) pre[j] += now[j]; 这句的解释
首先order表示的是每个数字排序之后的数组
order[0] 就是最小的那个数字是原来数组哪一个
但是会有等于的情况 所以这里定义的是如果
i < j时
* order[i] > order[j] 意味 A{order[i]] >= A[order[j]]
* order[j] < order[j] 意味 A[order[i]] < A[order[j]]
#include<vector>
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 1e5+5;
typedef long long ll;
int main(){
int n;
while(~scanf("%d",&n)) {
vector<int> low(n), high(n);
int m = 0;
for(int i = 0; i < n; ++i) {
scanf("%d %d",&low[i],&high[i]);
m = max(m, high[i]+1);
}
vector<ll> result(n+1);
vector<int> order(n);
for(int i = 0; i < n; ++i) order[i] = i;
do{
vector<ll> now(m);
for(int i = low[order[0]]; i <= high[order[0]]; ++i) now[i] ++;
for(int i = 1; i < n; ++i) {
vector<ll> pre(m);
ll sum = 0;
int lo = low[order[i]]; int hi = high[order[i]];
for(int j = 0; j < m; ++j) {
if(lo <= j && j <= hi) {
pre[j] = sum;
if(order[i] < order[i-1]) pre[j] += now[j];
}
sum += now[j];
}
now.swap(pre);
}
vector<int> dp(n,1);
for(int i = 0; i < n; ++i)
for(int j = 0; j < i; ++j)
if(order[j] < order[i]) {
dp[i] = max(dp[i], dp[j]+1);
}
int maxx = *max_element(dp.begin(), dp.end());
for(int i = 0; i < m; ++i)
result[maxx] += now[i];
}while(next_permutation(order.begin(), order.end()));
for(int i = 1; i <= n; ++i) {
if(i!=1) printf(" ");
printf("%lld",result[i]);
} printf("\n");
}
return 0;
}
2016弱校联盟十一专场10.2 Longest Increasing Subsequence的更多相关文章
- 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)
题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8506#problem/A problem description As we know, t ...
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)
题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C 代码如下: #include <iostream> # ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search
题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...
- (2016弱校联盟十一专场10.2) E.Coins
题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...
随机推荐
- Linux普通用户使用sudo权限启停apache服务
sudo的工作过程如下: 1,用户执行sudo时,系统会主动寻找/etc/sudoers文件,判断该用户是否有执行sudo的权限 2,确认用户具有可执行sudo的权限后,让用户输入密码确认 3,若密码 ...
- BZOJ 4555: [Tjoi2016&Heoi2016]求和 [FFT 组合计数 容斥原理]
4555: [Tjoi2016&Heoi2016]求和 题意:求\[ \sum_{i=0}^n \sum_{j=0}^i S(i,j)\cdot 2^j\cdot j! \\ S是第二类斯特林 ...
- Xposed快速hook关键点
0x01 导读 工作中,常常需要针对各种app进行快速代码定位,找到代码修改和调试各种功能,就不得不面对xposed来进行一系列快速定位关键代码的问题了.那么问题来了,如何快速找到代码呢? 这里值这针 ...
- Eclipse Java,debug模式无法调试,调试按钮不可用时解决办法
经常出现debug模式进入后,debug的几个按钮置灰,F5,6,8,没有任何反应时,这样操作: 退出 Eclipse.打开 Eclipse 目录下的 configuration 下的 org.ecl ...
- CentOS下安装go语言编译环境
1.下载Go语言的安装包 这里给大家一个百度的分享连接http://pan.baidu.com/s/1qY3xPaG下载到CentOS的系统之中 $ tar -xzf go1.5.2.linux-xx ...
- /dev/null 2>&1 详解
今天一个朋友突然在自己的维护的Linux中, /var/spool/cron/root 中看到了以下的内容: 30 19 * * * /usr/bin/**dcon.sh > /dev/nul ...
- [记录]一则清理MySQL大表以释放磁盘空间的案例
一则清理MySQL大表以释放磁盘空间的案例 一.基本情况: 1.dbtest库554G,先清理st_online_time_away_ds(37G)表的数据,保留半年的数据: 1)删除的数据:sele ...
- OKL4虚拟化技术跟踪
这篇博客准备介绍OKL4的研究进展,本文的内容主要根据我个人阅读<OKL4_LongPaper_2010_HW_VM>这篇文章之后的理解,我也根据这篇论文的内容做了一些实验,奈何此论文涉及 ...
- 搭建ssr服务器
搭建ssr服务器 首先,先说一下,为什么这么久没写博客. 一方面,最近在搭建自己的服务器.挺忙的. 另一方面,写了许多有关服务器构建,网站构建的word.但没有润色,所以打算等自己服务器做好了整理一下 ...
- C语言_指针变量的赋值与运算,很详细
指针变量的赋值 指针变量同普通变量一样,使用之前不仅要定义说明, 而且必须赋予具体的值.未经赋值的指针变量不能使用, 否则将造成系统混乱,甚至死机.指针变量的赋值只能赋予地址, 决不能赋予任何其它数据 ...