上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页
摘要: 思路:直接用long long 保存会WA。用下高精度加法就行了。#include#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 50010#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x=2;j--) update(nu... 阅读全文
posted @ 2013-09-04 15:06 fangguo 阅读(151) 评论(0) 推荐(0) 编辑
摘要: 思路:这是一道坑爹的动态规划,思路很容易想到,就是细节。用dp[t][i][j],表示在第t时间,锤子停在(i,j)位置能获得的最大数量。那么只要找到一个点转移到(i,j)收益最大即可。#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 2000010#define Maxm 80002#define LL __int64#define Abs(x) ((x)> 阅读全文
posted @ 2013-09-04 13:39 fangguo 阅读(278) 评论(0) 推荐(0) 编辑
摘要: 思路:简单动态规划#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 520#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x<<1)#define rson(x) (x<<1|1)#define inf 0x7ffff 阅读全文
posted @ 2013-09-03 15:55 fangguo 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 思路:简单树状数组#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 120#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x<<1)#define rson(x) (x<<1|1)#define inf 0x7ffff 阅读全文
posted @ 2013-09-03 15:03 fangguo 阅读(178) 评论(0) 推荐(0) 编辑
摘要: 思路:dp[i][j]表示区间i,j变为回文串最少的代价.#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 2002#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x=1;j--){ if(str[i]==str[j]){ ... 阅读全文
posted @ 2013-09-03 14:35 fangguo 阅读(219) 评论(0) 推荐(0) 编辑
摘要: 思路:裸的LCA#include#include#include#include#include#include#include#include#include#include#include#define pb push_back#define mp make_pair#define Maxn 40010#define Maxm 80002#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x > que[Maxn];void init(){ memset(head,-1,sizeof(head)); 阅读全文
posted @ 2013-09-02 21:36 fangguo 阅读(188) 评论(0) 推荐(0) 编辑
摘要: 思路: 每个点有三种状态,本身有塔,被子节点的塔覆盖,被父节点的塔覆盖。#include#include#include#include#include#include#include#include#include#include#include#define Maxn 10100#define Maxm 100010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x<<1)#define rson(x) (x<<1|1)#define inf 1000000#define Mo 阅读全文
posted @ 2013-09-02 13:58 fangguo 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 思路:dp[i][j]表示,以i节点为根,删去j个节点最少要断几条边。那么dp[u][j]=min(dp[u][j],dp[v][k]+dp[u][j-k]);//选取最优状态dp[u][j]=min(dp[u][j],dp[u][j-son[v]]+1);//切断与子节点相连的边对于子节点dp[v][n-son[v]]=1;dp[v][j]=min(dp[v][j],dp[v][j-n+son[v]]+1)//表示不需要由父节点过来的那条分支最有从所有状态中选举最优的dp[i][n-p];#include#include#include#include#include#include#inc 阅读全文
posted @ 2013-09-01 19:50 fangguo 阅读(143) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#include#include#include#include#include#include#include#include#define Maxn 100010#define Maxm 200010#define LL __int64#define Abs(x) ((x)>0?(x):(-x))#define lson(x) (x que[Maxn];void init(){ memset(head,-1,sizeof(head)); memset(vi,0,sizeof(vi)); memset(vis,0,sizeof... 阅读全文
posted @ 2013-09-01 15:37 fangguo 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 思路:我以前一直喜欢用根号n分段的LCA。在这题上挂了,第一次发现这样的LCA被卡。果断改用Tarjan离线算法求LCA。当前节点为u,其子节点为v。那么:当以v根的子树中含有连接子树以外点的边数为out[v]。out[v]==0,dp[u]+=m;out[v]==1,dp[u]+=1;else dp[u]+=0;最后就是dp[u]+=dp[v]。对于u点的out[u]+=out[v];最后out[u]-=cnt[u];cnt[u]表示以u为根,在子树内的边数。#include#include#include#include#include#include#include#include#in 阅读全文
posted @ 2013-09-01 15:34 fangguo 阅读(247) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 10 ··· 22 下一页