随笔分类 -  深搜广搜

摘要:思路:直接用优先队列优化bfs。#include#include#include#include#include#include#include#include#include#define Maxn 100010#define inf 1 g;int ans,n,ha[255],Exp[15];char s[13];int tar;struct QT{ int val,st; int operator temp.st; }};priority_queue q;int bfs(int temp){ int i,j,str; while(!q.empty()) q.... 阅读全文
posted @ 2013-12-26 17:19 fangguo 阅读(187) 评论(0) 推荐(0)
摘要:#include#include#include#include#include#define Maxn 100using namespace std;int dp[1<<21],num[Maxn],bag[Maxn][Maxn],g,b,s,now[22];bool vi[Maxn];int dfs(int S,int now[]){ if(vi[S]) return dp[S]; if(S==0) return 0; int a[22],c[22]; int i,j,f; int ans=-10000000; int num=0; vi[S]=1;... 阅读全文
posted @ 2013-10-29 14:00 fangguo 阅读(298) 评论(0) 推荐(0)
摘要:思路:定义一个四维状态的数组,记录每个状态先手的最优值。#include#include#include#include#include#define Maxn 30using namespace std;int ans[Maxn][Maxn][Maxn][Maxn],suma[Maxn],sumb[Maxn];void init(){ memset(ans,0,sizeof(ans)); memset(suma,0,sizeof(suma)); memset(sumb,0,sizeof(sumb));}inline int Max(int a,int b,int c,int... 阅读全文
posted @ 2013-08-25 09:16 fangguo 阅读(274) 评论(0) 推荐(0)
摘要:思路:分等号左边和右边进行搜索#include#include#include#include#include#define LL __int64using namespace std;char str[20];int n,ans;void right(LL sum,LL now,int cnt){ if(cnt==n) { if(sum==now) ans++; return ; } if(sum==0) return ; if(sum>=now*10+(LL)(str[cnt]-'0')) ... 阅读全文
posted @ 2013-08-20 13:53 fangguo 阅读(160) 评论(0) 推荐(0)
摘要:思路:直接搜索#include#include#include#includeusing namespace std;int belong[5010],num[5010],n;int dfs(int s,int pre,int cur){ int i,j; if(cur==n/2) return 1; for(i=s;ipre) { belong[j]=1; if(dfs(s+1,j,cur+1)) return 1; ... 阅读全文
posted @ 2013-08-09 14:11 fangguo 阅读(244) 评论(0) 推荐(0)
摘要:思路:就是找能走的走,遍历一边所有情况,满足就退出。Accepted4284328MS2280K2239 BC++//#pragma comment(linker, "/STACK:1024000000,1024000000")#include #include #include #include #include #include #define Maxn 110#define Maxm 6000#define LL int#define inf 100000000#define Abs(a) (a)>0?(a):(-a)using namespace std;in 阅读全文
posted @ 2013-07-29 14:42 fangguo 阅读(251) 评论(0) 推荐(0)
摘要:#include#include#include#include#includeusing namespace std;int len[22],n,El;int vi[22];int dfs(int k,int pos,int nowlen){ int i,j; if(nowlen==El) { if(k==n) return 1; else nowlen=0,pos=0; } for(i=pos;iMax) Max=len[i]; sum+... 阅读全文
posted @ 2013-07-08 20:43 fangguo 阅读(146) 评论(0) 推荐(0)
摘要:这题有两种解题思路,一个是记忆化搜索,一个是dp。分别贴代码:记忆化搜索:#include#include#include#include#includechar str[1000],a[300],b[300];int sum,flag;int hash[205][205];void dfs(int i,int j,int k){ if(flag) return ; if(k==sum) { flag=1; return ; } if(hash[i][j]) return ; hash[i][j]=1;... 阅读全文
posted @ 2013-07-08 14:59 fangguo 阅读(332) 评论(0) 推荐(0)
摘要:从原串的最大长度开始枚举,当某个长度的值能保存所有串时,即成功。对每个长度进行深搜,每次取某个串的第一个。#include#include#include#include#includeusing namespace std;char str[8][6];int flag=0,len[10],n;int getlen(int *a){ int i,ans=0; for(i=0;inowlen)//剩下的串中最短的串比预计长度要长 return ; if(nowlen==0)//找到,进行标记 { flag=1; return ;... 阅读全文
posted @ 2013-07-08 11:10 fangguo 阅读(160) 评论(0) 推荐(0)
摘要:这题我们可以用优先队列,每次弹出队列中操作次数最少的一个,那么当找到匹配数时,该值一定是最优的。需要注意的时,加个vi[]数组,判读当前数是否已经存在于队列中。我做的很烦啊~~~#include#include#include#include#include#includeusing namespace std;int n,m;int vi[100000];struct Point{ int n,num; Point(int x,int y) { vi[x]=1; n=x; num=y; } int operator te... 阅读全文
posted @ 2013-07-07 15:28 fangguo 阅读(168) 评论(0) 推荐(0)
摘要:#include#include#include#includeint vi[102][102][102];using namespace std;struct Point{ int a,b,c,v; Point(int x,int y,int z,int vv){a=x,b=y,c=z,v=vv;}};void pu(int &a,int &b,int c){ if(b==c) return ; if(a+b q; Point p(0,0,c,0); q.push(p); int s=c,n=a,m=b; while(!q.emp... 阅读全文
posted @ 2013-07-05 06:20 fangguo 阅读(182) 评论(0) 推荐(0)
摘要:这题的思想很简单,就是每次找出队列里面花费时间最少的来走下一步,这样当我们找到k点后,所花费的时间一定是最少的。但要用一个标记数组vis[200010],用来标记是否走过。否则会内存溢出。#include<queue>#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int vis[200010];struct Point{ int position,Time; Point(int a,int b) { position=a;Time=b; vis[a 阅读全文
posted @ 2013-06-21 13:41 fangguo 阅读(275) 评论(0) 推荐(0)