2013年8月19日
摘要: 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394题意:给一个0-n-1的排列,这个排列中的逆序数为数对 (ai, aj)满足 i aj的个数。依次把第一个数放到排列的末尾会得到另外n-1个排列,求这n个排列中的最小的逆序数。思路:关键是要把第一个排列的逆序数求出来,后面的排列可以递推出来。假如第一个逆序数为s0,当把a0从首位移到末位时,新得到的s1应该是在s0的基础上加上比a0大的数的个数,减去比a0小的数的个数。由于这一串数是一个0-n-1的排列,所以比a0大的数的个数为 (n-1)-(a0+1)+1=n-a0-1,比a0小的数的个数为 . 阅读全文
posted @ 2013-08-19 21:52 ∑求和 阅读(751) 评论(0) 推荐(0) 编辑
摘要: 链接:http://codeforces.com/problemset/problem/4/D题意:有一张卡片,若干张信封,它们有个长和宽。要求,找到数量最多的一串信封,这一串信封满足信封的长和宽都是严格递增的,而且卡片的长和宽要比最小的信封小。思路:先对长度排个序,然后求宽度的最长上升子序列。要处理好长度相等的信封。#include#include#include#include#include#include#includeusing namespace std;const int maxn=5005;int dp[maxn],c[maxn];struct en{ int w,h,f... 阅读全文
posted @ 2013-08-19 21:06 ∑求和 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 链接:http://poj.org/problem?id=1631题意:最长上升子序列。复杂度为O(n*logn).思路:这道题只能用nlogn的算法,n^2的话会卡掉。下面这两个个链接介绍nlogn的算法讲的还可以。http://www.cnblogs.com/celia01/archive/2012/07/27/2611043.htmlhttp://blog.sina.com.cn/s/blog_4b1e4fe9010098af.html代码如下:#include#include#include#include#include#include#includeusing namespace 阅读全文
posted @ 2013-08-19 15:51 ∑求和 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1136题意:裸的最长上升子序列。复杂度O(n^2).#include#include#include#include#include#include#includeusing namespace std;const int maxn=1005;int n;int a[maxn],dp[maxn];int LIS(){ dp[0]=1; int ans=1; for(int i=1;is && a[j]ans) ans=dp[i];... 阅读全文
posted @ 2013-08-19 11:21 ∑求和 阅读(183) 评论(0) 推荐(0) 编辑