自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(109)
  • 收藏
  • 关注

原创 codeforces Beautiful Numbers

枚举 sum = ai + b(n - i)C[n][i] = fact[n]inv(fact[n - i]fact[i]).inv(a) is multiplicative inverse element(moduloMOD).MOD is a prime number, soinv(a) = aMOD - 2.乘法逆元解决 除法中模的方法代码:#include

2013-05-14 01:00:40 695

原创 codeforces 168 div2 Zero Tree

http://codeforces.com/contest/275/problem/D发点题证明自己在做题对于每个节点 记录他的孩子节点中最大的减少的值 和 最大的增加值 执行到该点的时候必须执行的步骤是key-sub+add代码:#include #include #include #include #include #include #include #inclu

2013-05-14 00:43:36 633

原创 hdu 1503 Advanced Fruits

http://acm.hdu.edu.cn/showproblem.php?pid=1503最长公共子序列 用个p[i][j]记录dp[i][j]是从哪个位置传递过来的然后dfs输出,基本都是看的别人题解,然后自己写的,就不多说了代码:#include #include #include #include #include #include #include #inc

2012-11-17 12:07:53 487

原创 hdu 1502 Regular Words

http://acm.hdu.edu.cn/showproblem.php?pid=1502catalan数,可以直接套公式这里居然有DP方程,太神了dp[i][j][k]=dp[i-1][j][k]+dp[i][j-1][k]+dp[i][j][k-1];i-1>=j>=k,i>=j-1>=k,i>=j>=k-1 这里要分别讨论初始化也是个问题方程解释一下,dp[i]

2012-11-16 21:43:07 571

原创 hdu 3008 Warcraft

http://acm.hdu.edu.cn/showproblem.php?pid=3008dp[i][j]表示第i秒 魔法值为j的时候对BOSS的伤害这里用递推,因为你的魔法是在所有攻击完后才会增加#include #include #include #include #include #include #include #include #include using

2012-11-16 10:31:11 1013

原创 hdu 1227 fast food

http://acm.hdu.edu.cn/showproblem.php?pid=1227 dp[i][j]=min(dp[i-1][k]+cost[k+1][j],dp[i][j]);dp[i][j]表示供应点个数为i的时候对于前j个位置,最小的sum这里i到j这个区间中 取一个点使之所有点到这个点取得最小的距离和 那么这个点必定在(i+j)/2的位置cost[i][j]表示i

2012-11-14 16:07:59 437

原创 hdu zipper 1501

http://acm.hdu.edu.cn/showproblem.php?pid=1501记忆化搜索由于第三个串是由 前两个串按顺序组成的 那么从前两个串的 第一位 和 第三个串的第一位 开始比 相等就比下一个能比到尾就行了从这些路径中找出可行的 记忆化搜索代码:#include #include #include #include #include #incl

2012-11-14 00:05:37 552

原创 poj 2485 Highway

http://poj.org/problem?id=2485最小生成树 模板题kruscal算法代码:#include #include #include #include #include #include #include #include #include using namespace std;int p[505];struct node{

2012-11-12 22:27:17 446

原创 hdu 1422 重温世界杯

http://acm.hdu.edu.cn/showproblem.php?pid=1422暴力水过,正解应该是DP最长非负子序列a[i]为第i个 生活费-花费if(sum[i-1]+a[i]>=0){    dp[i]=dp[i-1]+1;    sum[i]=sum[i-1]+a[i];    maxn=max(maxn,dp[i]);}else

2012-11-12 21:40:26 473

原创 hdu 1074 Doing Homework

http://acm.hdu.edu.cn/showproblem.php?pid=1074状态压缩DP 的模板题学习了一下状态压缩DP这里处理字典序的方法 有排序,貌似排序的还简单一些我用的指针signp指向上一个状态,p指向状态对应取的字符串代码:#include #include #include #include #include #inclu

2012-11-12 18:51:14 522

原创 hdu 1059 Dividing

http://acm.hdu.edu.cn/showproblem.php?pid=1059多重背包 用二进制优化 本来还想直接从小到大放的那个方法 貌似只适用于完全背包代码:#include #include #include #include #include #include #include #include #include using namespace

2012-11-11 09:38:23 448

原创 hdu 1158 Employment Planning

http://acm.hdu.edu.cn/showproblem.php?pid=1158dp[i][j] 表示第i月留j个人最少的话费代码:#include #include #include #include #include #include #include #include #include using namespace std;#define Deb

2012-11-11 02:11:50 460

原创 hdu 2059 龟兔赛跑

http://acm.hdu.edu.cn/showproblem.php?pid=2059一开始想多了代码基本上抄的 关键是没搞懂为什么不考虑加油为什么也能 AC仔细一看 原来j=0的时候就已经把每个状态的不加油的情况考虑进去了代码:#include #include #include #include #include #include #include #i

2012-11-10 23:05:39 471

原创 hdu 1081 To The Max

http://acm.hdu.edu.cn/showproblem.php?pid=1081转换成 最大连续子序列就行了代码:#include #include #include #include #include #include #include #include #include #include using namespace std;int matrix

2012-11-09 21:57:19 378

原创 hdu 1078 FatMouse and Cheese

http://acm.hdu.edu.cn/showproblem.php?pid=1078哈哈 记忆化搜索 第一次自己写的过了努力终于有回报了啊^-^代码:#include #include #include #include #include #include #include #include #include using namespace std;in

2012-11-09 19:35:36 426

原创 hdu 1025 Cstructing Roads

http://acm.hdu.edu.cn/showproblem.php?pid=1025对p进行排序,然后就是对rich的最长上升子序列的求法,只是o(n^2)的算法不行,要用d[i]表示序列长度为i时,最小的数为d[i],查找的时候用二分查找,查完的在把最小的放进去代码:#include #include #include #include #include #in

2012-11-09 14:44:10 477

原创 hdu piggy-bank 1114

http://acm.hdu.edu.cn/showproblem.php?pid=1114完全背包求最小值这题貌似正着求一次 用个二维就行了我的方法有点2B 反着求 用了二进制优化二维的懒的写了代码:#include #include #include #include #include #include #include #include #in

2012-11-07 12:35:03 438

原创 hdu 2191 HDU 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

http://acm.hdu.edu.cn/showproblem.php?pid=2191简单多重背包题目代码:#include #include #include #include #include #include #include #include #include using namespace std;int f[105];struct node{

2012-11-07 00:21:36 596

原创 hdu 1978 How many ways

http://acm.hdu.edu.cn/showproblem.php?pid=1978DP好吧,我不能很好的理解题目的意思做法就是从每个点出发能到的曼哈顿距离的点就全部加上此点的路径数先是DP写法,准备在写个记忆化搜索练习下代码:#include #include #include #include #include #include #inclu

2012-11-06 00:17:58 378

原创 codeforces 148 div2 C

http://codeforces.com/contest/239/problem/C到第i位就有i-1种子序列组成的不同值 例如m=2时 1 2,有1和1^2,那么如果n=3的话就只能放一个从i=1递推过去代码:#include #include #include #include #include #include #include #include #in

2012-11-05 15:46:51 472

原创 codeforces 148 div2 B

http://codeforces.com/contest/239/problem/B蛋疼的模拟题 并不难 直接模拟就行 郁闷 codeforces上的题目总是看的蛋疼 老是看不懂要么搞错题意 比赛时候看题就浪费快半个小时 而且好像还忽略了某个条件代码贴着做教训代码:#include #include #include #include #include #inclu

2012-11-05 11:57:02 424

原创 hdu 1789 Doing Homework again

http://acm.hdu.edu.cn/showproblem.php?pid=1789这题贪心 每次找分数最多的看能不能全部完成 不能的话就舍去 去找下一个这个我还真没想到 看题解才知道 这题隐蔽性真大 还有就是判断能不能全部完成那里 我卡主了 蛋疼代码:#include #include #include #include #include #include #

2012-11-04 22:52:19 337

原创 hdu 1421 搬寝室

http://acm.hdu.edu.cn/showproblem.php?pid=1421先排序然后dpdp方程为:dp[i][j]=min(dp[i-2][j-1]+(num[i]-num[i-1])^2,dp[i-1][j]);表示到i之前(包括i)搬j对需要的最少疲劳值注意处理好一下边界就好代码:#include #include #include #in

2012-11-03 17:52:29 375

原创 hdu 1159 Common Subsequence

http://acm.hdu.edu.cn/showproblem.php?pid=1159最长公共子序列不解释代码:#include #include #include #include #include #include #include #include #include using namespace std;char word1[1005];char w

2012-11-03 11:36:57 366

原创 hdu 2830 Matrix Swapping II

http://acm.hdu.edu.cn/showproblem.php?pid=2830先求出每一行的高度,然后对于每一行有多少个 存在高度 用个hash存起来后面枚举的时候 先排序从大到小,然后 二维只枚举到hash存起来的数就行了,排序是为了方便求对于每一行求矩阵且节省时间,因为0的就跳过了矩阵求法 ans=max(height[i][j]*j,ans); 因为前面大的

2012-11-02 22:57:18 334

原创 codeforces 241 A

http://codeforces.com/contest/241/problem/A这题感觉很经典 就写了一下这题贪心,每次如果不能到达某个地方,就一直最后在前面的城市中选油田供给最多的去加油,我也这么想过,但不知道怎么实现,应该收很麻烦看了大神的代码后豁然开朗,其实就用一个变量记录到这个方面前面最多油田的供给量,然后每次不能到时候去加这个就行了代码:#include #i

2012-11-02 12:37:54 417

原创 hdu 2870 Largest Submatrix

http://acm.hdu.edu.cn/showproblem.php?pid=2870和1506 和1505类似的解法一个关键的优化就是if(!num[j])  continue;说实话不是想不到,关键是懒的加,因为看起来不可能优化多少现在知道了,以后能优化的尽量优化,这个不加就是超时与不超时的关系代码:#include #include #inclu

2012-11-02 00:28:43 390

原创 hdu 2845 Beans

http://acm.hdu.edu.cn/showproblem.php?pid=2845dp[i]表示在i之前(包括i) 最大得的分数dp[i]=(dp[i],dp[i-2]+matrix[i]);每一行这么求一次,然后最后一列竖着求一次因为我不知道他的分数会不会为负数,所以我用的max有三个变量代码:#include #include #include #i

2012-11-01 12:39:59 334

原创 hdu 2844 coins

http://acm.hdu.edu.cn/showproblem.php?pid=2844多重背包+二进制优化学习了一下 二进制优化卡在了 二进制的判定那           int len=0;           int num=1;           while(w[i]-num*2+1>0)           {               d[len

2012-10-31 23:01:04 372

原创 hdu 2577 How to Type

http://acm.hdu.edu.cn/showproblem.php?pid=2577关键是处理好边界dp方程见代码:#include #include #include #include #include #include #include #include #include #include using namespace std;int on[10

2012-10-29 23:49:14 349

原创 hdu 2159 FATE

http://acm.hdu.edu.cn/showproblem.php?pid=2159二维完全背包方程f[s,m]=max(f[s,m],f[s-v[i],m-1]+m[i]);v是疲劳度 m是经验值找的时候疲劳度放外层循环找代码:#include #include #include #include #include #include #include

2012-10-29 19:41:22 424

原创 hdu 1203 I NEED A OFFER!

http://acm.hdu.edu.cn/showproblem.php?pid=120301背包代码:#include #include #include #include #include #include #include #include #include using namespace std;double f[10005];struct node{

2012-10-29 15:57:54 395

原创 hdu 1171

http://acm.hdu.edu.cn/showproblem.php?pid=1171背包问题先全部装进去 然后考虑一半这题真心数据太弱了 弄几次最坏样例 就会挂了代码:#include #include #include #include #include #include #include #include #include using name

2012-10-29 14:42:47 501

原创 hdu 1069

http://acm.hdu.edu.cn/showproblem.php?pid=1069先排序 然后类似 最大上升子序列的 求法代码:#include #include #include #include #include #include #include #include #include using namespace std;struct blocks

2012-10-28 11:32:56 530

原创 hdu 2571 命运

http://acm.hdu.edu.cn/showproblem.php?pid=2571一开始就有了思路了不过中途各种边界问题和初始化问题,而且方程也写错了方程dp[i][j]=max(dp[i-1][j]+maps[i][j],dp[i][j-1]+maps[i][j]);and while(sign           {

2012-10-26 12:38:09 499

原创 codeforces147 div2 C题

http://codeforces.com/contest/237/problem/C二分l,枚举x,赛后才做出,读题能力有待加强代码:#include #include #include #include #include #include #include #include #include #include #include using namespac

2012-10-26 12:30:10 631

原创 hdu 2602

http://acm.hdu.edu.cn/showproblem.php?pid=2602简单01背包,但这道题要卡你骨头重量为0的数据,因为重量为0就可以无限放了,这题按照那种优化空间复杂度的那种倒着DP的方法 能秒A但按普通那么写的同学就悲剧了 我这里提供以下这种写法这是要把容量从0枚举而已,而且要把上一次的状态继承下来代码:#include #include #in

2012-10-25 12:09:14 672

原创 hdu 1505

hdu 1506的加强版看了大牛的思路才会做对每一行做一次1506的算法不会的看博客hdu 1506http://blog.youkuaiyun.com/talak/article/details/8108137 代码:#include #include #include #include #include #include #include #include #i

2012-10-25 11:00:13 363

原创 hdu 1506

http://acm.hdu.edu.cn/showproblem.php?pid=1506用DP 用l[i] 和r[i]存对应位的左边界 和右边界但找左右边界的时候不能暴力找 要迭代的方法找 不然会超时左:while(l[i]-1>0&&num[l[i]-1]>=num[i]){     l[i]=l[l[i]-1];}边界出来了 面积好算了吧就这样代码:

2012-10-24 17:40:59 444

原创 hdu 4006

简单multiset 的应用代码:#include #include #include #include #include #include #include #include #include using namespace std;int main(){ multiset hashs; int n,k; while(scanf("%d%d"

2012-10-24 16:33:42 533

空空如也

空空如也

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

TA关注的人

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