随笔分类 -  枚举

HDU 4407 sum 容斥原理
摘要:算法:利用数据1...N的性质,求与P的互质的个数,位运算,容斥定理。。#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;struct info{ int s,e 阅读全文

posted @ 2012-09-22 21:07 more think, more gains 阅读(339) 评论(0) 推荐(0)

B.寻找最大值
摘要:算法:1.正向思维如果枚举区间求最值肯定TLE,数据量很大。2.反向思维,枚举每个点的左右区间,虽然两个for循环,我感觉是平均是O(N)的时间复杂度,动态规划的思想,可以求出。3.这题相当诡异,不能给dt数组清空赋值,坑了我一晚上加上午,还不知道为什么。4.我的L[I]记录的是该点能往左到达的边界,R【i]是往右到达的边界。旭他们记录的是以该点向左能扩张的长度,R【i]类似。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#incl 阅读全文

posted @ 2012-08-18 09:38 more think, more gains 阅读(188) 评论(0) 推荐(0)

Expression 暴力枚举
摘要:算法:可以枚举所有状态,然后排序。View Code #include<stdio.h>#include<string.h>#include<stdlib.h>#include<vector>#include<algorithm>#include<iostream>#include<stack>#include<string>using namespace std;char str[1000];int f[1000];int main( ){ int T; scanf("%d", 阅读全文

posted @ 2012-07-31 07:50 more think, more gains 阅读(202) 评论(0) 推荐(0)

poj 2965 枚举搜索
摘要:这题跟POJ1753 flip game 思想一样。。唯一不同得是这题要保存方案。用c++一直超时,g++500多ms.View Code #include <stdio.h>#include <string.h>#include <iostream>#include <queue>#include <stack>using namespace std;int visit[70000];char mp[1100];struct node{ int state; int num;}p;struct pnode{ int x, y;}px 阅读全文

posted @ 2012-07-08 19:58 more think, more gains 阅读(150) 评论(0) 推荐(0)

poj 1753 Flip game 枚举
摘要:BFS搜索 + 位运算提速。。枚举每一个状态, 进行up, left, down, right操作。。当状态state = 0xffff 或0时,说明全部为黑或白。。。对于一个状态没有访问过就入队,并且标志为已访问。。View Code #include <iostream>#include <cstdlib>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <queue>using namespace std;char mp[100];int 阅读全文

posted @ 2012-07-08 17:02 more think, more gains 阅读(152) 评论(0) 推荐(0)

导航