这个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. HDU 4825 Xor sum

    trie树的异或和问题 本题是一道经典题,使用trie树维护所给出的集合,我们知道等比数列前n项的和比第n+1项小,所以本题可以使用贪心策略,对于每一个询问,我们从高位向低位匹配,寻找最大异或值,向下 ...

  2. python重新利用shodan API

    前言: 之前写过一个shodan的API调用 感觉写的不这么好.然后现在重新写一个 shodan介绍: shodan是互联网上最可怕的搜索引擎. CNNMoney的一篇文章写道,虽然目前人们都认为谷歌 ...

  3. LeetCode - 776. Split BST

    Given a Binary Search Tree (BST) with root node root, and a target value V, split the tree into two ...

  4. angularjs 控制器、作用域、广播详解

    一.控制器 首先列出几种我们平常使用控制器时的几种误区: 我们知道angualrJs中一个控制器时可以对应不同的视图模板的,但这种实现方式存在的问题是: 如果视图1和视图2根本没有任何逻辑关系,这样& ...

  5. 机器学习之支持向量机(三):核函数和KKT条件的理解

    注:关于支持向量机系列文章是借鉴大神的神作,加以自己的理解写成的:若对原作者有损请告知,我会及时处理.转载请标明来源. 序: 我在支持向量机系列中主要讲支持向量机的公式推导,第一部分讲到推出拉格朗日对 ...

  6. 初学Python(第一课)

    今天整理一下关于Python初学者的基础知识部分的第一课,因为之前学习过C,所以过于基础的知识就不详细记录了. Python相对于C\C++来说,在语法方面已经很简单了:甚至对于JavaScript也 ...

  7. Centos下_MysqL5.7在使用mysqldump命令备份数据库报错:mysqldump: Got error: 1449: The user specified as a definer ('fk_system'@'localhost') does not exist when using LOCK TABLES

    在阿里云服务器增加一个shell脚本定时备份数据库脚本执行任务时,测试性的执行了备份命令,如下 [root@iZ2ze503xw2q1fftv5rhboZ mysql_bak]# /usr/local ...

  8. PHP结合Redis来限制用户或者IP某个时间段内访问的次数

    $redis = new Redis(); $redis->connect('127.0.0.1', 6379); //获取客户端真实ip地址 function get_real_ip(){ s ...

  9. 2道acm简单题(2010):1.猜数字游戏;2.字符串提取数字并求和;

    //第一题是猜数字的游戏.//题目:随即产生一个3位的正整数,让你进行猜数字,//如果猜小了,输出:"猜小了,请继续".//如果猜大了,输出:"猜大了,请继续" ...

  10. PV和UV的简单记录

    1.什么是PV值 PV(page view)即页面浏览量或点击量,是衡量一个网站或网页用户访问量.具体的说,PV值就是所有访问者在24小时(0点到24点)内看了某个网站多少个页面或某个网页多少次.PV ...