摘要: 思路:从一维扩展到三维。可以看看poj2155的解法。#include#include#include#include#define Maxn 102#define lowbit(x) (x&(-x))using namespace std;int C[Maxn][Maxn][Maxn],n;int Sum(int i,int j,int k){ int sum=0; int y,z; y=j,z=k; while(i) { j=y; while(j) { k=z; while(... 阅读全文
posted @ 2013-07-31 21:17 fangguo 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 思路:首先就是状态压缩,然后判断哪些状态是回文串。最后就是动态方程:dp[i]=min(dp[i],dp[j]+1)。这个方程得前提条件是状态(j-i)为回文串。#include#include#include#define inf 1=0;i--) { dp[i]=inf; for(j=i+1;j<=n;j=((j+1)|i)) { if(pl[j-i]) dp[i]=min(dp[i],dp[j]+1); } ... 阅读全文
posted @ 2013-07-31 18:04 fangguo 阅读(252) 评论(0) 推荐(0) 编辑
摘要: 思路:这题的处理方式和hdu4358有点像。我们用一个pre[x]表示约数x的倍数上次出现的位置,将查询按区间的右节点升序排序。num[i]的约数为j,如果pre[j]为0,就将pre[j]置为i;否则就update(pre[j],j),表示的意思是约数j肯定不是第一次出现,将pre[j]以前的区间更新最大约数。如果查询区间的右边界在i处,那么左边界在pre[j]以前就肯定就能取到j。因为num[pre[j]]和num[i]有一个公共约数j,且pre[j]和i被该查询区间所覆盖。#include#include#include#include#define Maxn 50010#define 阅读全文
posted @ 2013-07-31 17:59 fangguo 阅读(401) 评论(0) 推荐(1) 编辑
摘要: 思路:从后面往前面插,用一个二维树状数组保存,c[i][0]表示比i小的元素和,c[i][1]表示比i小的元素个数。#include#include#include#include#define Maxn 100010#define lowbit(x) (x&(-x))using namespace std;__int64 C[Maxn][2],n,num[Maxn],cnt;__int64 Sum(__int64 pos){ __int64 sum=0; while(pos) { sum+=C[pos][0]; cnt+=C[pos][1]; ... 阅读全文
posted @ 2013-07-31 10:16 fangguo 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 思路:加一个数e就用update(e,1)。删除元素e就用update(e,-1)。找比a大的第k大的元素就用二分查找。#include#include#include#include#define Maxn 120010#define lowbit(x) (x&(-x))using namespace std;int C[Maxn];int Sum(int pos){ int sum=0; while(pos) { sum+=C[pos]; pos-=lowbit(pos); } return sum;}void update(int... 阅读全文
posted @ 2013-07-31 09:23 fangguo 阅读(118) 评论(0) 推荐(0) 编辑