摘要: 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394分析:树状数组的应用。Minimum Inversion Number 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define maxn 5005 7 using namespace std; 8 int c[maxn],num[maxn],n; 9 int low_bit(int i)10 {11 return i&(-i);12 }13 void update(int i,int v)14 {15 w... 阅读全文
posted @ 2013-08-16 22:06 EtheGreat 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 求逆序数的方法有很多,比如归并排序,但本文重点讲一下如何用树状数组来求逆序数。 当数据的范围较小时,比如maxn=100000,那么我们可以开一个数组c[maxn],来记录前面数据的出现情况,初始化为0;当数据a出现时,就令c[a]=1。这样的话, 欲求某个数a的逆序数,只需要算出在当前状态下c[a+1,maxn]中有多少个1,因为这些位置的数在a之前出现且比a大。但是若每添加一个数据a时,就得从a+1到 maxn搜一遍,复杂度太高了。树状数组却能很好的解决这个问题,同样开一个数组d[maxn],初始化为0,d[i]记录下i结点所管辖范围内当前状态有多少个数;当添加数 ... 阅读全文
posted @ 2013-08-16 21:45 EtheGreat 阅读(2850) 评论(2) 推荐(1) 编辑
摘要: 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1003分析:定义dp[i][1]表示到第i个数时的最大连续和,dp[i][1]表示dp[i][0]取到最大值时的左边起始位。Max Sum 1 #include 2 #include 3 #include 4 #include 5 #define maxn 100005 6 using namespace std; 7 int num[maxn],dp[maxn][2]; 8 int main() 9 {10 int T,cas=1;11 scanf("%d",&T);1 阅读全文
posted @ 2013-08-16 20:43 EtheGreat 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010分析:dfs+奇偶剪枝。Tempter of the Bone 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 char s[10][10]; 7 bool visit[10][10],flag; 8 int dx[4]={0,0,1,-1}; 9 int dy[4]={-1,1,0,0};10 int n,m,t,di,dj;11 void dfs(int time,int i,int j)12 {13 阅读全文
posted @ 2013-08-16 20:33 EtheGreat 阅读(214) 评论(0) 推荐(0) 编辑