- 博客(34)
- 收藏
- 关注
原创 组队赛2 - 2014.7.20 - 2013长春现场赛
B - Golden Radio BaseproblemthinkcodeC - Little Tiger vs. Deep Monkeyproblemthinkcode
2014-07-21 15:06:44 670
原创 HDU-4008-treeDP
这题看好多天了。为什么看那么久呢?因为对于我来说有点难,难了就不能静心了,一会看人人一会聊天的。又不想看别人的思路。今天终于静下心来想了。我想的和网上baidu google 到的都不太一样。上代码 。int son1[N], son2[N], fa[N]; //向下最大 向下次大 向上最大 儿子int dw1[N], dw2[N], up[N]; //向下最大
2012-09-01 10:50:54 1063
原创 HDU-4049-状压
求助:::::::::://城市的顺序从1到m,不懂为什么 。。 还是顺序没有影响 。。const int inf = 1<<30;const int N = 1111;int next[N][N], num[N], mny[N][12];int cost[12], val[12][12], with[12][12];int dp[N][12]; int n, m,
2012-08-20 16:35:42 624
原创 POJ-3162-treeDP+线段树
const int N = 1000009;int dw1[N]; //向下最大int dw2[N]; //向下次大int up[N]; //向上最大int m[2][N<<2]; //线段树的最值int n, mm;vector >v[N];void dfs1(int s) //向下最大和向下次大{ dw1[s] = dw2[s] = 0; int i, ss
2012-08-15 09:43:16 694 1
原创 POJ-1741-treeDP+分治
。。。const int inf = 0x3f3f3f3f;const int N = 10009;int dis[N], vis[N];int size[N], hash[N];int sum[N];//子孙数 ;int big[N]; //儿子的最大子孙数int n, k, ans, cnt;vector >v[N];void num_child(int s
2012-08-13 16:21:47 873
原创 POJ-2152-treeDP
const int inf = 1<<30;const int N = 1009;int dp[N][N]; //dp[i][j] i依赖与j时的最优解int w[N], d[N];int dis[N][N]; //每两个节点之间的距离int best[N]; //每个节点为根的子树的最优解 best[i] = min( dp[i][j] ) (1<=j<=n)vector >v[N
2012-08-12 14:51:13 820
原创 HDU-4044-treeDP+分组背包
我觉得这题挺难想的。反正我是想了好久。题意:一棵树(编号1-n),1是敌人出口(只有一个敌人)。叶子节点是我军。在节点处装大炮。每个节点有 k 种大炮选择,可是每个节点最多装一个大炮。每个大炮有一个花费和一个威力值。你一共有m钱,怎么能使威力值最大。敌人去攻击哪个我军是任意的,所以最大威力是每条路值和的最小值。大炮放在叶子节点也是管用的。解题思路:每个节点最多装一个大炮,所以是分组
2012-08-12 14:29:24 1156
原创 HDU-4354-treeDP
枚举区间。[l, r]开始 l = r = 1, 记录已经出现的国家。判断是否满足条件。如果满足,更新答案,更新区间出现的国家,l++, 一直到不满足。如果不满足,更新区间出现的国家,r++, 一直到满足。const int C = 5005;const int N = 2005;const int M = 1005;int cnt[N]; //i国家出现过
2012-08-11 15:36:55 709
原创 HDU-4358-树状数组+离散化
这题是看了解题报告做的。第二种方法一直 TLE 。 是我写挫了 。第一种是树状数组。给每个节点一个起始位置和结束位置。这些位置值与节点标号没有关系。这样1-n 都会作为起始位置。给他们新的权值。从1-n依次枚举,这里枚举的不是节点编号,而是位置。枚举到i时,树状数组的query(k) 求得的是k位置到i位置的答案。查询时,按每个查询的点的结束位置从小到大排序。这样枚举到i位置,
2012-08-11 15:22:50 717
原创 HDU-4359-DP+C(n, m)大数求
比赛的时候一直在敲这道题。一开题就盯住这个名字了。有人说他说是 treeDP 不一定真的是 treeDP。总有时候别人会给你很诚恳的忠告。却只因自己陷得太深无法自拔。关键是自己不想出去。跑题了。读错题了。n,d. d 是说 深度恰好为 d , 我给理解为不超过 d 。 于是最后答案变成 ans(n,d) - ans(n, d-1) 就可以了。C(n, m) 那个东西 , 由于里
2012-08-11 15:13:08 2578
原创 HDU-4351-线段树
这题纠结了好久。状态转移,预处理的话要1024*1024*10*10,感觉会T,然后发现 9 当成 0 就变成了 512*512*9*9,于是就这么写了。然后 T 了好久, 然后各种改 , IO加速。能加 inline 的都加 inline 。 依然 TLE 。后来找一下别人的代码 , 发现 查询的时候 , 我是在每个查询里面 分别再查询 左右值。别人都放一个结构体里面,这样别人的
2012-08-11 14:46:58 624
原创 多校五。
HDU-4340-treeDP这题一看就是树DP。可是当时我想错了。伤心死了。。后来看到解题报告 dp[N][2][2], 瞬间就都懂了 。。 可是没用了 。。 没用了 。。dp[i][2][2] //一维表示以谁为节点的子树; 二维第几个人; 三位这棵子树有几个全价。转移方程,以第0个人为例,同理第1个人。j,k是i的不同孩子。dp[i][0][0] = cost[i][0]
2012-08-09 00:38:05 683
原创 HDU - 4332 - 多校四1002 - 矩阵+状压
#include #include #include #include #include #include #include using namespace std;__int64 tri[300][300];int ok[300];int pos[300];int sta;struct node{ __int64 x[300][300];}tmp[35],
2012-08-03 12:36:21 1413
原创 POJ-1442-treap
#include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;const int N = 30009;const double esp = 1e-6;int v[N];struct treap{ tre
2012-07-09 14:36:37 1234
原创 POJ-2486-树背包
一直想把他当树dp做 。。 怎么也想不出来转移方程 。。 后来灵机一动 。。 很像背包啊 。。 于是今天到机房就把他敲了 。。好久好久好久没做背包了 。。虽然某种说法上背包也是dp 。。const int K = 209;const int N = 109;int dp[2][N][K];//0表示不回来;1表示回来int val[N];int vis[N];int n
2012-07-09 08:50:28 640
原创 POJ-4045-数据结构+dfs
#include #include #include #include #include #include using namespace std;const int maxn = 50009;__int64 start[maxn];__int64 end[maxn];__int64 child[maxn];__int64 val[maxn];int vis[maxn];
2012-07-08 09:57:17 605
原创 POJ-4052-ac自动机
先把匹配上的串都标记。然后把每个匹配上的串的子串变成非结束。直接会超时。优化找失败指针的地方。#include #include #include #include #include #include #include using namespace std;const int maxn = 250009;char str1[5100009], str2[51
2012-07-08 09:55:07 912
原创 POJ-4047-线段树
#include #include #include #include #include #include #include using namespace std;const int maxn = 200009;int n, nn, m, k; int a[maxn], b[maxn];struct tree{ int l, r, v, lazy, mid;
2012-07-08 09:47:17 489
原创 HDU-3695-ac自动机
char str1[5100009], str2[5100009];int cnt;struct trie{ trie *ch[26]; trie *fail; int end; void init() { memset(ch, NULL, sizeof(ch)); fail = NULL; end =
2012-07-07 13:56:22 644
原创 HDU-3658-矩阵
#include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 1009;const double esp = 1e-6;const __int64 mod = 1000000007;
2012-07-07 13:54:12 425
原创 HDU-2852-树状数组+第k小数
int C[maxn];int lowbit(int x){ return x&(-x);}void updata(int pos, int tmp){ for(; pos<=100000; pos+=lowbit(pos)) C[pos] += tmp;}int query(int pos){ int a = 0; for(;
2012-07-07 13:45:59 1056
原创 HDU-3887-树状数组
一看这题简单啊 。。 于是写 。。于是wa 。。。传说中的暴栈 。。。人工写 。。 对我来说还是挺难的 。。。注释掉的就是暴栈的 。。int start[maxn];int end[maxn];int vis[maxn];int C[maxn];int ans[maxn];int ans1[maxn];int ans2[maxn];int stac
2012-07-07 13:43:27 590
原创 POJ-1185-状态dp
int dp[109][161][161];char mp[109][15];int sta[61];//int nn[61];void init(){ int tol=0, i, j; for(i=0; i<=1024; i++) { int num = 0; for(j=0; j<10; j++) {
2012-07-07 13:37:47 399
原创 POJ-1739-插头dp
int dp[10][10][19690]; //传说中的三进制int bit[]={1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683};char ok[13][13];int st[1000][10], go[19900], p[900][10], slack[10];int k, num, tot;int main(){ int n
2012-07-07 13:35:32 800
原创 POJ-3208-dp
(有点ac自动机思想(和POJ1037一样,输出麻烦 。。__int64 dp[15][4];int s[4][10] = { {0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 2, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 3, 0, 0, 0},
2012-07-07 13:29:03 773
原创 POJ-3691-ac自动机+dp
const double esp = 1e-6;int dp[1009][1009];int cnt;struct trie{ trie *ch[4]; trie *fail; int id; bool end; void init() { memset(ch, NULL, sizeof(ch)); fail
2012-07-07 13:27:43 617
原创 HDU-1693-插头dp
懂了这道题还不算懂插头dp。我现在就是不懂插头dp。要想懂插头dp就要先懂状态dp。状态dp之于插头dp,就像 trie树之于ac自动机。__int64 dp[13][13][1<<13];int ok[13][13];int n, m;int main(){ int t; scanf("%d", &t); for(int tt=1; t
2012-07-07 13:26:32 931
原创 POJ-1037-dp
(一到普通的dp , 整了好久才AC。。dp只记录个数,输出时需要逻辑 。。__int64 dp[22][22][2];int ans[22];int vis[22];void init(){ memset(dp, 0, sizeof(dp)); dp[1][1][0] = 1; dp[1][1][1] = 1; for(int i=2; i<
2012-07-07 13:22:54 624
原创 POJ-2440-矩阵
const int inf = 0x3f3f3f3f;const int maxn = 1009;const int mod = 2005;const double esp = 1e-6;int x[5][5]={ {1, 1, 0, 0, 0}, {0, 0, 1, 1, 0}, {0, 0, 0, 1, 1},
2012-07-07 13:21:21 517
原创 POJ-1848-treedp
dp[][3]dp[i][0] 表示第i个节点和他所有孩子们都在一个环里了(i在环里);dp[i][1] 表示第i个节点的孩子们都在一个环里了(i不在环里);dp[i][2] 表示第i个节点除了一条孩子链的其他孩子都在环里了(i不在环里)。int vis[109];int dp[109][3];struct node{ int ch[109]; in
2012-07-07 13:19:10 547
原创 POJ-2778-ac自动机+矩阵
(这道题是我的第一道动态矩阵。以前做过ac自动机,做过静态矩阵。于是很想做这道题。可是自己就是想不出来思路。后来是和芳哥一起讨论整理出的思路。非常非常感谢芳哥。。后来我写的时候,半个小时敲完,然后一直wa,发现有个bug,如(GA, AT)那么G后面的C转向状态0,但是我写的trie里面G后面没有C 。 于是我各种想办法。 这种时候,不要找度娘。 因为度娘告诉我很多我看不懂得方法。于是还是自己想。
2012-07-07 13:12:00 530
原创 ZOJ-3612-树状数组+第k小数+离散化
#include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 10009;const double esp = 1e-6;double bef[maxn];double aft[m
2012-07-07 13:07:39 1386
原创 POJ-2761-树状数组+第k小数+离散化
#include #include #include #include #include #include #include using namespace std;const int inf = 0x3f3f3f3f;const int maxn = 100009;const double esp = 1e-6;int n, m, num;int bef[maxn];
2012-07-07 13:05:29 1273
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人