自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(28)
  • 资源 (1)
  • 收藏
  • 关注

原创 hdu 3667 Transportation 费用流

很明显的费用流的题目,把一条边拆成5条即可。#include #include #include using namespace std;const int maxn=1e2+9;int n,m,p;int head[maxn],lon;struct{ int next,to,c,w,from;}e[222222];void edgeini(){ mems

2013-11-30 23:31:04 915

原创 Codeforces Round #216 (Div. 2) D. Valera and Fools

这个题目很多人都是用记忆化搜索的办法来做的,确实这样比较不容易错并且好写。不过我用了另外一种办法,枚举加判断,判断dp[i][j]是否可行,首先计算前j-1个人死亡的最少回合数,然后再看看后i个人是否不存在神枪手,再判断j号人物是否具有杀伤力,然后再把之前的回合数加上杀死j到i的人的回合数,看看是否比k小,如果这些条件都满足,则这个状态可达。然后剩下的问题就是怎么计算前j-1个人死亡的

2013-11-30 13:21:12 1280

原创 hdu 4117 GRE Words 11年成都现场赛

离线建树,然后按顺序把值插入,每插入一个值的时候就按着fail算出该节点的最优解。一个优化,那些值小于0的节点直接去掉。#include #include #include #include using namespace std;const int maxn=3e5+9,N=26,root=0,maxm=2e4+9;int cas=0;int lon;struct{

2013-11-29 15:14:44 910

原创 hdu 4114 dp

ans[i][j],i表示去过的景点和拿到的票的状态,j表示现在在哪个景点。然后spfa即可#include #include #include using namespace std;const int maxn=59;int n,m,p;int cost[10][2];int a[maxn][10],top[maxn];int num[maxn];int tt=0;

2013-11-26 22:15:11 1022

原创 hdu 4125 树状数组+kmp

这个建树的过程用了树状数组+二分找区间的做法,很麻烦。#include #include #include #include #include using namespace std;const int maxn=6e5+9;int a[maxn];char s[maxn<<1];int top,tt=0,f[maxn];char c[maxn];int n;int l

2013-11-26 19:43:20 715

原创 csdn 4090 GemAnd Prince

写了个最朴素的dfs#include #include #include using namespace std;int a[10][10],sum[10],ans;int n,m,k;int quex[111],quey[111],front,end;bool chk(int t,int s,int use[10][10]){ int ret=0; int x

2013-11-25 21:15:11 785

原创 hdu 4085 斯坦纳树

#include #include #include using namespace std;const int maxm=11e2+9,maxn=10e1+9;int dp[maxm][maxn],num[maxn],d[maxn][maxn];int n,m,k;bool visit[maxn],chk[maxm];void getdp(){ memset(dp,50

2013-11-25 16:59:03 1126

原创 hdu 4123 Bob’s Race 树形dp+单调队列

树形dp求树上最长距离,然后单调队列维护。#include #include #include #include using namespace std;const int maxn=5e4+9;vector > e[maxn];int n,m;int dist[maxn][2];void dfs(int t,int from){ for(vector >::

2013-11-24 18:25:33 938

原创 hdu Holiday's Accommodation dfs

#include #include #include #include #define ll long long#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std;const int maxn=1e5+9;vector > e[maxn];int n;int son[maxn]

2013-11-24 02:39:45 1059

原创 hdu 4115 Eliminate the Conflict

2sat题目,正确理解2sat即可。#include #include #include using namespace std;const int maxn=(1e4+9)*2;int n,m;int a[maxn][2];int dfn[maxn],low[maxn],stack[maxn],instack[maxn],s[maxn],un[maxn];int count

2013-11-24 02:05:48 1209

原创 poj 1389

求矩形的面积并#include #include #include #include using namespace std;const int maxn=1101;int ans;struct{ int l,r,x; int y1,y2; bool ture; int count;}tr[10000];struct data{

2013-11-23 20:59:15 976

原创 hdu 4059 The Boss on Mars 容斥原理

容斥原理的题目,用容斥来做还是比较明显,关键是要去推那个4次方的公式。然后注意公式里面要除以30,那么就先求%(mod*30),然后再除以30再%mod。#include #include #include #include #define ll long longusing namespace std;const ll mod=1e9+7;int a[1111],lon;

2013-11-23 20:30:57 927

原创 hdu 4089 概率dp

带循环的概率dp但是这个题目的问题是精度很难处理,为什么不特判p4就a不了,表示不能理解。#include #include #include using namespace std;const int maxn=2e3+9;int n,m,k;double p1,p2,p3,p4;double dp[maxn][maxn];void solve(){ mems

2013-11-23 16:01:48 903

原创 poj 2151 Check the difficulty of problems dp

概率dp的题目,不过我的做法可能比较不一样,先计算出每个人答对1~n-1,n~m道题目的概率。然后dp[i][0] 表示前i个人,有一个人至少答对n道题,并且每个人至少一个题目的概率。dp[i][1] 表示前i个人,每个人至少答对一道题目的概率。状态转移就很明显了。#include #include #include using namespace std;const in

2013-11-22 14:09:33 945

原创 hdu 4468 spy kmp+dp

首先可以用递推的思想来考虑,如果已经求得了dp[i]的答案,怎么得到dp[i+1]的答案。这个dp值是不考虑最后一个字符需要完整的。只需要判断所有以i+1个字符为结尾的串中有没有一个是现在的模式串的前缀,有的话证明dp[i]的值就是dp[i+1]的值。否则这个i+1号字符及它之前的还未匹配的串就一定要加入到模式串中。#include #include #include using

2013-11-20 21:34:38 1318

原创 hdu 4704 费马小定理

费马小定理+快速幂费马小定理可以用来求解a的高次幂mod质数的值。前提是a与质数互质。#include #include #include using namespace std;const int maxn=1e6+9,mod=1e9+7;char a[maxn],s[111]={0,'1','0','0','0','0','0','0','0','0','6'};bool

2013-11-20 14:42:37 1073

原创 hdu 4248 A Famous Stone Collector dp+组合数学

预处理出c[10000][100],然后dp递推。#include #include #include #define ll long longusing namespace std;const int maxn=1e4+9,mod=1e9+7;ll dp[maxn],c[maxn][111];int a[maxn];int n,sum;ll getdp(){ m

2013-11-19 23:32:32 1130

原创 2013 成都 hdu 4784 Dinner Coming Soon dp

这个题目虽然描述的比较麻烦,但是还是不难的,因为t是递增的,所以有拓扑序,那么就可以用dp解了。dp[i][j][p][q] 表示在i点,j宇宙,p时间,q包盐的最优解。但是这个题目最大的问题是让人容易用spfa来解,因为复杂度看起来还是可以的。。。。可是tle到死。#include #include #include using namespace std;const int

2013-11-18 22:30:19 1052

原创 hdu 4790 Just Random 数论

成都赛区的j题,表示没有想到太好的做法,就用了个比较麻烦的,先把问题转换成%p==0的a+=p-m;b+=p-m;m=0;#include #include #include #define ll long longusing namespace std;long long a,b,c,d,p,m;long long x,y;long long cal(ll a,l

2013-11-18 19:17:53 1330

原创 hdu 4779 Tower Defense

组合数学的题目,很明显这个题目的难点在于重塔的设定,所以一定要从重塔下手,但是一直因为一个误区没找到办法。题解的办法,先枚举有两个重塔的行和列,再枚举独占行列的塔中的重塔数量。#include #include #include using namespace std;const int maxn=2e2+9,mod=1e9+7;int n,m,p,q;long long pp

2013-11-18 17:18:55 1496

原创 hdu 4436 str2int 后缀数组

递推的办法不难想到,但是要去重,那就要后缀数组来找最长前缀了。后面递推的没想好,写搓了。#include #include #include #include #include using namespace std;const int maxn=1e5+1e5+9,mod=2012;char a[maxn];int r[maxn];int next[maxn];lon

2013-11-13 00:49:51 1072

原创 hdu 4466 Triangle

对于长度为n的三角形的个数是靠打表找出来的规律,就不解释了。然后这个三角形最大公约数为1,那么就可以用筛选法来做。最后计算答案就o(n)扫描的计算,这个比较简单,不解释了。#include #include #include using namespace std;const int maxn=5e6+111,mod=1e9+7,N=5e6;int sum[maxn],p

2013-11-12 00:28:15 960

原创 hdu 4776 Ants 杭州现场赛G题

杭州现场赛的题目,首先求出每个节点到根节点的xor值,那么两个节点路径的xor值就等于他们到根节点的xor值再xor。那么就会有n*n个xor值,但是题目值要求前面的k个,并且k小于200000.那么就可以这么搞了,先找xor之后最高位为1的,看看有多少个,如果大于k,那么证明前k大的全部在里面,再找次高位的就可以,否者,把这些数全部找出来并排序,剩下的再在这一位不为一的那里找。#

2013-11-10 23:41:51 2526

原创 hdu 4426 Palindromic Substring 字符串hash

这个题目真的wa了两天,最后居然是求最长回文子串的地方边界条件没有处理好,真心跪了。#include #include #include #include #include using namespace std;const int maxn=4e5+9,maxm=11371111;;const long long mod=777777777;char a[maxn];i

2013-11-09 11:00:59 1213

原创 hdu 4429 Split the Rectangle

读懂题意之后就是简单的暴力找一个最小的矩形去包围这两个点,然后把这个矩形内部的点全部去掉,就可以得出答案。#include #include #include using namespace std;const int maxn=2e3+9,inf=1e9;int n,q;int lonl,lonr;struct{ int x1,x2,y1,y2;}line[m

2013-11-06 20:15:43 911

原创 hdu 4424 Conquer a New Region 并查集

去年长春的时候没做出来,现在看起来也并不困难,反着把大的边开始加就好。#include #include #include #include using namespace std;const int maxn=2e5+9;int n;int fa[maxn];long long sum[maxn],son[maxn];struct E{ int from,to

2013-11-04 20:12:31 721

原创 hdu 4099 Revenge of Fibonacci

暴力求出前十万的斐波那契数列,然后存储起来,后面再查找就好了。存储的话建议两种方式,一种是字典树,一种是hash,当然这个题目用字典树会更好。#include #include #include #pragma comment(linker, "/STACK:36777216")using namespace std;const int mod=10;struct add

2013-11-04 19:42:44 762

原创 poj 1966 Cable TV Network

枚举源点和汇点。#include #include #include using namespace std;const int maxn=109,inf=1e8;int n,m;int a[maxn][maxn];int que[maxn],level[maxn];int head[maxn],lon;struct{ int next,to,c;}e[max

2013-11-02 00:23:37 945

poj 3947 题解

经典O(n)求最长回文 acmer新手可看

2013-09-24

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除