这个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的更多相关文章

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

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

  3. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  4. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  5. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

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

  7. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  8. (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search

    题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...

  9. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

随机推荐

  1. 用icas下载文件报错

    前段时间服务器升级,过程中测试到报表下载,报表下载要用到icas,用的是sdts-client.jar,但是此jar包有两种连接模式,分别为: public static final SdtsConn ...

  2. 洛谷 [P2420] 让我们异或吧

    某两点之间的路径上所有边权的异或值即dis1^dis2--^disn. 由于x^y^y=x,所以dfs预处理出每一点到根节点的异或值,对于每次询问,直接输出 disu^disv. #include & ...

  3. bzoj 1598: [Usaco2008 Mar]牛跑步 [k短路 A*] [学习笔记]

    1598: [Usaco2008 Mar]牛跑步 题意:k短路 ~~貌似A*的题目除了x数码就是k短路~~ \[ f(x) = g(x) + h(x) \] \(g(x)\)为到达当前状态实际代价,\ ...

  4. bzoj 4823: [Cqoi2017]老C的方块 [最小割]

    4823: [Cqoi2017]老C的方块 题意: 鬼畜方块游戏不解释... 有些特殊边,有些四个方块组成的图形,方块有代价,删掉一些方块使得没有图形,最小化代价. 比较明显的最小割,一个图形中必须删 ...

  5. js跨域解决方案

    1.参考该文档:http://blog.csdn.net/enter89/article/details/51205752 2. 参考网络:http://www.ruanyifeng.com/blog ...

  6. virtualbox命令行共享CentOS目录

    virtualbox命令行共享CentOS目录   1. 安装virtualbox增强工具 "右ctrl+c" 显示和隐藏virtualbox虚拟机的菜单栏. 在VirtualBo ...

  7. centos 7 双网卡建网桥脚本实现

    #!/bin/bash interface1=`ls /sys/class/net|grep en|awk 'NR==1{print}'` interface2=`ls /sys/class/net| ...

  8. PyCharm安装Pygame方法

    最近在自学Python,然后终于到了项目实战的时候了,而且还是做一个游戏,热情直接被调动起来了,嘿嘿 首先要安装一个Pygame 环境 win7 先去 这里 下载对应Python的Pygame版本 如 ...

  9. RHEL6误安装RHEL7的包导致glibc被升级后系统崩溃处理方法

    RHEL6误使用了RHEL7的光盘源,安装了某个RPM包之后,导致glibc被升级,进而导致系统崩溃.   [root@rhel65 ~]# yum install ftp Loaded plugin ...

  10. c的文件流读取

    strtok(数组,分隔符); atof(数组)返回值为转换后的数字; fgets(数组指针,长度,文件句柄); 整整花了两天啊