自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

嗯。

嗯。

  • 博客(32)
  • 资源 (2)
  • 收藏
  • 关注

原创 ZOJ 3538 Arrange the Schedule / 矩阵快速幂

老师开的DP专题 说题目不难 我看了这题 n很大 以前做过很多n很大的 然后是矩阵快速幂加速的DP DP方程很好推 打了一下草稿 2*2的01矩阵要是没有m个限制那就是水题了 m最多才10 我想了下 可以分成m+1段矩阵快速幂来求 遇到那几个限制的天数的时候就单独用一个矩阵乘一下这样的题目做的很少 写了几个小时 最后1A 题目不算难 细心点 矩阵构造很简单 纸上写一下如果第x天必须

2014-03-31 18:17:21 1175

原创 Ural 1303. Minimal Coverage / 最小区间覆盖

求最小区间覆盖0-m 以前做过 现在墨迹半天写出来 弱爆了像这样的1 9 和 2 7 根据贪心原理后者不需要然后按照起点 在按照终点 从小到大排序 贪心模拟一下每次能不选就不选 #include #include #include using namespace std;const int maxn = 100010;struct node{ int s, e;}a[m

2014-03-31 14:35:11 1152 2

原创 URAL 1260. Nudnik Photographer

虽然是简单递推 找规律 这种DP还是做得少 没有感觉参考http://hi.baidu.com/xiaozhao_club/item/aec3d7c898d56d390831c6da#include __int64 a[60];int main(){ a[1]=1; a[2]=1; a[3]=2; for(int i = 4; i <= 55; i++

2014-03-31 11:35:39 1020

原创 HDU 1520 Anniversary party / 树形DP水题!!!

考虑取和不去 dp[u][0]代表u为根的树不取 儿子v可以取可以不取dp[u][1]代表取u 然后儿子v不能取 水题1A#include #include #include #include using namespace std;const int maxn = 6010;vector G[maxn];double dp[maxn][2];int a[maxn];int

2014-03-30 17:26:00 990

原创 ZOJ 1163 The Staircases / 01背包

每个物品选一次 完全背包#include #include const int maxn = 510;double dp[maxn];int main(){ memset(dp, 0 ,sizeof(dp)); dp[0] = 1; for(int i = 1; i <= 500; i++) { for(int j = 500; j >= i; j--) { d

2014-03-30 15:47:53 1170

原创 POJ 2063 Investment / 体积变大的完全背包

完全背包  体积都是1000的倍数 所以可以除以1000 可能你会想价值是1000的倍数啊 这没关系买股票 买x元的股票1年可以增加y元 现在总共有m元 求k年后 最多有多少钱每年做一次完全背包 #include #include #include using namespace std;const int maxn = 100010;int dp[maxn];int a[

2014-03-28 17:40:31 1210

原创 POJ 3260 The Fewest Coins / 混合背包

给钱+找钱花的硬币最少 给钱多重背包 找钱01背包 然后背包上限不知道 据说是抽屉原理 我还没学过 然后有空在学多重背包我用2进制优化01背包 以为是要在多重背包的基础上减 背包的价值是负数所以 我是倒过来处理的#include #include #include using namespace std;const int maxn = 130;const int max

2014-03-28 13:38:31 995

原创 POJ 1787 Charlie's Change / 完全背包

多重背包 不过用完全背包来做 加个判断当前硬币的数量是否超过限制 还有就是打印路径 觉得打印路径都差不多 UVa打印路径的题目很多 要是字典序要求就更高了#include #include using namespace std;const int maxn = 10010;int dp[maxn], num[maxn], p[maxn];int a[10];int b[10]

2014-03-28 11:24:56 1024

原创 ZOJ 3469 Food Delivery / 区间DP

区间DP 这题也是看着别人的代码写下来的 效果也不是很大 鄙视下自己  主要是自己作业还没做完 心急了一点 还被人催着做C#实验 有空写一下记忆化搜索版本区间DP一般都是dp[l][r] 表示l到r这段区域的最优值 然后区间逐渐扩大 可以写成递推的 也可以记忆化搜索这题还要加一维 代表当前的位置实在区间的最左边还是最右边dp[l][r][0]代表在最左边l的位置 可以从dp[l+1][

2014-03-27 17:16:44 930

原创 POJ 3345 Bribing FIPA / 树形DP

基本题吧 错了好几次 G[0]没清空 从1开始清空了 伤不起 其他没什么难度#include #include #include #include #include #include using namespace std;const int maxn = 210;vector G[maxn];int dp[maxn][maxn];int a[maxn];int sum

2014-03-27 14:08:23 999

原创 POJ 2441 Arrange the Bulls / 状态压缩DP

还是比较简单的 入门的DP#include #include const int maxn = 22;int dp[2][1<<maxn];int pre[1<<maxn];int a[maxn][maxn];int main(){ int n, m; scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) { scan

2014-03-27 12:11:38 1038

原创 POJ 2752 Seek the Name, Seek the Fame / KMP

做了HDU 3336 这题小casek=next[n] 是最长的前缀 这题还要求不是最长的前缀 那么就 k = next[k]#include #include const int maxn = 400010;const int mod = 10007;char a[maxn];int f[maxn];int dp[maxn];int n, flag;void print

2014-03-25 16:16:01 1098

原创 HDU 3746 Cyclic Nacklace / KMP

首先 t = n-next[n]是周期 n是字符串长度 如果 n%t = =0 那么该字符串是一个周期串如果n%t !=0  t还是周期 只不过末尾多一部分 话句话说 该字符串是由若干个t和一段字符x组成 如果没有x那么它就是一个周期串 并且x和t的开头是相同的 就是x是t的前缀那么x的长度是多少呢 是n%t既然x是t的前缀 就满意补上一些字符使x变成t 补多少字符呢 t-n%t ,

2014-03-25 12:42:53 896

原创 HDU 3336 Count the string / KMP

都是找和前缀一样的有多少个 想到KMP然后要求的不是最长的前缀 只要是前缀都算 因此巧妙的借助Next数组 再来一个dp 有点前缀和的思想不好说 慢慢揣摩#include #include const int maxn = 200010;const int mod = 10007;char a[maxn];int f[maxn];int dp[maxn];int n, m;

2014-03-25 11:00:30 858

原创 POJ 3461 Oulipo / KMP

基础KMP 开始学AC自动机了 先搞清楚KMP#include #include using namespace std;const int maxn = 1000010;char a[maxn], p[maxn];int f[maxn];void getFail(){ int m = strlen(p); f[0] = f[1] = 0; for(int i = 1; i

2014-03-24 16:09:59 808

原创 TOJ 3886 Simplifying the Farm / 最小生成树+计数

懒得讲了 #include #include #include #include #include using namespace std;const int maxn = 100010;const int mod = 1000000007; struct edge{ int u, v, w;}a[maxn];int n, m;int f[maxn];int fin

2014-03-23 21:47:55 1002

原创 HDU 1561 The more, The Better / 树形DP

树形DP 选m个节点权值加起来最大因为可能是森林 就是都没有限制就可以选 去一个超级源点0 这样就是一棵树了然后就是基础的树形DP了 DP方程很好想 也很好转移#include #include #include using namespace std;const int maxn = 210;struct node{ int v, w;};vector G[max

2014-03-21 22:55:52 936

原创 POJ 1155 TELE / 树形DP

树形DP 其中有分组背包 第一个循环是每一组 就是以u为根的若干子树 然后第二个循环是枚举背包体积 从大到小 因为是滚动 第三个循环是枚举每一组的物品 3个循环不能颠倒 以为是分组背包 每组的物品只能选一个 具体这题就是子树不能有重叠 每个点不能选多次#include #include #include using namespace std;const int maxn = 30

2014-03-21 20:19:30 1024

原创 POJ 1837 Balance / 分组背包

n个位置放m个砝码 求天平的平衡有几种方案分组背包 每个物品是一个组 总个m个物品m组 每个组有n个 因为每个物品可以在n个位置中任何一个此外这题又是与负数 还是平移可以滚动 因为不卡内存 所以没写滚动 写滚动还要考虑正负#include #include #include const int maxn = 30;int a[maxn], b[maxn];int dp[m

2014-03-20 15:56:36 1062

原创 HDU 3033 I love sneakers! / 分组背包

有k类物品 至少每种选一个 求最大价值考虑只有一类物品 那么就是01背包了 现在k类 那就多加一维好了 dp[i][k] = max(max(dp[i][k], dp[i][k-x]+y), dp[i-1][k-x]+y);#include #include #include #include using namespace std;const int maxn = 110;

2014-03-20 12:43:08 990

原创 POJ 2392 Space Elevator / 体积不定的多重背包

对于体积不变 可以先排个序 这样对于体积大的物品 转移时比他小的状态都算出来了#include #include #include using namespace std;const int maxn = 444;struct block{ int a, b, c;}a[maxn];int dp[maxn*100];bool cmp(block a, block b)

2014-03-19 12:43:21 860

原创 HDU 2639 Bone Collector II / 第K大的01背包

第k大可以多加一维状态对于第i个物品 每次求出不放这个物品的时候 第1到第k大的数 就是上一维的情况 再求出放这个物品时候第1到第k大的数 得到2*k个价值 求出2*k个数中最大的k个然后题目要求严格递减 不能一样#include #include const int maxn = 110;int dp[maxn][maxn*10][33];int a[maxn], b[max

2014-03-18 16:24:22 1019

原创 POJ 2923 Relocation / 状态压缩DP

和以前做的差不多n《=10 很容易忘状态压缩那里想预处理一下 哪几个物品可以一次运完 可以的话用一个二进制表示 并且dp[state] = 1 表示一次就可以然后平常那样做状态压缩DP就行了 #include #include #include #include using namespace std; const int maxn = 12;const int INF

2014-03-17 22:39:17 924

原创 TOJ 3481 Highway Construction / 树的直径+SPFA

首先求出树的直径 然后把直径上的点都放近队列 做一次SPFA 求出最短路 求出最短路的最长路径即可树的直径就是树上最远2点的路径 在直径上建这条路可以是答案尽量小 然后就可以做最短路了还是很弱 比赛看出是树的直径没敢写 这方面练得不够多吧 #include #include #include using namespace std;const int maxn = 100010

2014-03-15 20:57:29 1087

原创 ZOJ 2856 Happy Life / 太暴力了 我不会啊!!

#include #include using namespace std;const int maxn = 210;int a[maxn][maxn];int ans[maxn];int main(){ int n; while(scanf("%d", &n) !=EOF) { for(int i = 1; i <= n; i++) { for(int j =

2014-03-14 12:11:06 1622

原创 UVa 11008 Antimatter Ray Clearcutting / 状态压缩DP

一看题目就知道是状态压缩 DP然后n棵树至少要砍掉m棵每次可以去掉一整行的树 斜着也可以 求最少的次数开始不知道怎么存一整行 百度了 然后是用一个二维数组a[i][j] 里面一个二进制 表示可以朝i j这个发现去掉的树然后i == j的时候我是 a[i][j] = 1网上大多数是记忆化搜索 递推也行还需好好消化#include #include #include

2014-03-13 12:51:00 1222

原创 UVa 10201 Adventures in Moving - Part IV / 恶心的DP!!!伤不起

不会做DP的孩子伤不起dp[i][j]表示到第i个站剩下油j的最小花费油最满200起点0 有100升到终点是至少要留下100升写了三个for可以优化到2个for 没能力 以后有空在优话说UVa的题目越做越难了 伤不起#include #include #include using namespace std;const int maxn = 210;int

2014-03-12 21:52:27 1069

原创 UVa 607 Scheduling Lectures / 分不出什么类型的DP!!!

有n个主题。每堂课的时间是L。每个主题各要求t1,t2,...tn(1现在每堂课有m分钟 求最小需要几堂课 可以讲完这些主题 然后是满意度尽量低 满意度怎么算题目有图因为一定要按照顺序讲每个主题 然后就可以贪心求出最小需要的课堂数dp[i][j] 代表 i堂课 讲j个主题最小的满意度然后推吧dp[i][j] = min(dp[i][j], dp[i-1][k]+ok(m-(su

2014-03-12 13:44:54 1038

原创 UVa 10911 Forming Quiz Teams / 状态压缩DP

小白书上讲的很详细n对点 两两配对 求每对点的距离之和最小状态压缩DP 经典#include #include #include #include using namespace std;const int maxn = 18;double dp[1<<maxn];double x[maxn];double y[maxn];double d(int i, int j

2014-03-12 11:55:54 1030

原创 UVa 10304 Optimal Binary Search Tree / 区间DP

还是很弱 二叉树啊 没忘区间dp想啊 搜解题报告了使劲戳这里吧http://blog.csdn.net/hcbbt/article/details/15776963看懂了姐写了个记忆化搜索#include #include #include using namespace std;const int maxn = 255;int a[maxn];int sum[maxn

2014-03-10 19:54:00 975

原创 HDU 4284 Travel / 状态压缩DP

最多15个必须经过的城市 2进制表示dp[i][j] 表示i这个状态下现在位置是第j个城市剩下的最大钱数我日啊 id有一个错了 害我哇了12次 #include #include #include using namespace std;const int maxn = 110;int INF = 999999999;struct Li{ int u, c, d;}b

2014-03-07 09:30:58 1000

原创 TOJ 4489 You are a Boss / 线段树成段更新

没什么好说的啊 练基本功啊时间戳+线段树成段更新+单点查询用dfs时间戳找出每个人管的属下 low high 每次成段更新 唉 #include #include #include using namespace std;const int MAX = 500010;int b[MAX];int c[MAX];int low[MAX];int high[MAX];

2014-03-04 10:54:55 1197

ACM 学习资料

ACM 学习资料 包括一些压缩包 和 数据结构的一点东西

2013-11-29

数据结构课件

数据结构的课件 感觉比书上的代码容易理解

2013-09-04

空空如也

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

TA关注的人

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