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 ...
随机推荐
- POJ2891 Strange Way to Express Integers [中国剩余定理]
不互质情况的模板题 注意多组数据不要一发现不合法就退出 #include <iostream> #include <cstdio> #include <cstring&g ...
- 《深入理解Java虚拟机》——Java内存区域与内存溢出异常
程序计数器(Program Counter Register):一块较小的内存空间,可看作是当前线程所执行的字节码的行号指示器.字节码解释器工作时通过改变这个计数器的值来选取下一条需要执行的字节码指令 ...
- ThinkPHP删除栏目(多)
前段时间发表了一个删除栏目的随笔,当时实现的功能是删除一条信息,这次来实现一下批量删除栏目. 我们需要达到的是这样一个效果: 选中批量删除按钮后可以选中所有该页面的栏目,这个是前端页面的实现,在这里就 ...
- Java实现单链表的快速排序和归并排序
本文描述了LeetCode 148题 sort-list 的解法. 题目描述如下: Sort a linked list in O(n log n) time using constant space ...
- iterm2 快捷键大全
Mac 原来自带的终端工具 Terminal 不好用是出了名的,虽然最近几个版本苹果稍微做了些优化,功能上,可用性方面增强不少,无奈有个更好用的 Iterm2 摆在那,基本上也就没有多少出场机会了 I ...
- [SDOI2015]序列统计
[SDOI2015]序列统计 标签: NTT 快速幂 Description 给你一个模m意义下的数集,需要用这个数集生成一个数列,使得这个数列在的乘积为x. 问方案数模\(1004535809\). ...
- 让Python输出更漂亮
print 默认输出是换行的,如果要实现不换行需要在变量末尾加上 end="": student_age = 18 print("学生的年龄为:", stude ...
- Dynamics CRM 2015-Ribbon In Basic Home Tab
前文中有说到关于Form上Ribbon的配置以及控制,而Ribbon Button还可以在其它地方的配置,今天就来说说在Basic Home Tab里面的配置,效果图如下: 具体配置Customiza ...
- centos/linux下的安装vsftpd
1.简介: vsftpd 是“very secure FTP daemon”的缩写,安全性是它的一个最大的特点.vsftpd 是一个 UNIX 类操作系统上运行的服务器的名字,ftp服务器软件 2.安 ...
- 关于HTTP,你知道哪些?
HTTP简介 HTTP 的全称是 Hypertext Transfer Protocol,超文本传输协议 规定客户端和服务器之间的数据传输格式 让客户端和服务器能有效地进行数据沟通 HTTP 协议是网 ...