![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
计算机算法设计与分析
文章平均质量分 63
Crystal_oscillator
这个作者很懒,什么都没留下…
展开
-
稳定婚姻问题
<br />//稳定婚姻问题a1[N][N],a2[N][N]为优先秩矩阵int mm[N],mf[N],ms[N];int match(int u){ int i,j,k,p=n+1; for(i=1;i<=n;i++) if(a1[u][i]<p&&ms[u]<=a1[u][i]){ k=i; p=a1[u][i]; } if(mf[k]==0){原创 2010-11-10 08:45:00 · 846 阅读 · 0 评论 -
TopCoder SRM558 backup 1 DIV 2
Problem Statement Surrounding Game is a single-player game played on a rectangular grid of cells. Cells are considered adjacent if they share a common side. (Hence, each cell has at most fo原创 2012-10-20 09:38:23 · 679 阅读 · 0 评论 -
1-SRM 144 DIV1
Problem Statement Let's say you have a binary string such as the following: 011100011 One way to encrypt this string is to add to each digit the sum of its adjacent digits. For exa原创 2012-06-10 20:25:36 · 861 阅读 · 0 评论 -
数的全排列
<br />#include<iostream>#include<cstring>#define N 4using namespace std;int rec[N];bool used[N];int count=0;void Print(){ for(int i=0;i<N;i++) cout<<rec[i]<<" "; cout<<endl;}void Try(int s){ int j=0; w原创 2011-04-19 22:37:00 · 478 阅读 · 0 评论 -
求高效算法
<br />请用回溯法解决骑士巡游问题(骑士巡游问题是指:在8*8的国家象棋棋盘上,一匹马从任意位置出发,按照象棋的规则走,要求踏遍整个棋盘,并且每个格子只能经过一次)。<br />#include<iostream>#include<cstring>#define N 8using namespace std;bool v[N][N];int a[N][N],sx,sy,d[8][2]={{-2,-1},{-1,-2},{1,-2},{2,-1},{-2,1},{-1,2},{1,原创 2011-04-20 20:58:00 · 644 阅读 · 0 评论 -
老鼠走迷宫
<br />老鼠走迷宫:用一个二维数组a[m][n]表示迷宫,数组元素0表示通路,为1表示墙壁。老鼠在除边角外的任意位置都可以试探8个方向<br />。请用回溯法求出从入口a[0][0]到出口a[m-1][n-1]的通路。<br />#include<iostream>#include<cstring>#define N 1000using namespace std;bool v[N][N];int a[N][N],path[N*N][2],step,m,n,d[8][2]={{-原创 2011-04-20 18:03:00 · 761 阅读 · 0 评论 -
0/1背包问题
Charm Bracelet<br />Description<br />Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the supplied list has a原创 2011-03-31 22:04:00 · 777 阅读 · 0 评论 -
最大子段和问题
<br />int f(int a[],int n){ int ans,i; sum[0]=a[0]; ans=sum[0]; for(i=1;i<n;i++) { if(0<sum[i-1]) sum[i]=sum[i-1]+a[i]; else sum[i]=a[i]; if(ans<sum[i]) ans=sum[i]; } return ans;}原创 2011-03-29 19:37:00 · 451 阅读 · 0 评论 -
Longest Ordered Subsequence
Longest Ordered Subsequence<br />DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example原创 2011-03-29 17:07:00 · 631 阅读 · 0 评论 -
棋盘覆盖问题
<br />Source Code:<br /> <br />#include<iostream><br />#include<cstdio><br />#include<cstring><br />using namespace std;<br /> <br />const int N=1024;<br /> <br />int board[N][N],count;<br /> <br />void cover(int sx,int sy,int cx,int cy,int size,int cx1[],原创 2011-03-09 13:11:00 · 462 阅读 · 0 评论 -
农夫问题--状态空间搜索
#includeusing namespace std;const int N=100;bool q[16],visited[16];int path[N];void printpath(int count){ static int cnt=0; printf("Solution %d:/n",cnt++); for(int i=0;i>3,(path[i]&4)>>2,(path[i]&2)>>1,path[i]&1); pri原创 2011-02-24 22:53:00 · 3597 阅读 · 0 评论 -
最大生成树
Heavy TransportationTime Limit: 3000MS Memory Limit: 30000KDescriptionBackground Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the原创 2010-11-15 21:44:00 · 2155 阅读 · 0 评论 -
最小生成树 堆
struct qnode{ int v,c; qnode(int v1=0,int c1=0):v(v1),c(c1){} bool operator r.c; }};//最小生成树,堆int mstfa(int n){ int i,j,ans=0,v,c; priority_queue q; for(i=0;i原创 2010-11-15 15:54:00 · 677 阅读 · 0 评论 -
2-sat
vector g[N];int n,id[N],pre[N],low[N],s[N],stop,cnt,scnt;void tarjan(int v,int n){ int i,t,minc=low[v]=pre[v]=cnt++; s[stop++]=v; for(i=0;i原创 2010-11-13 22:38:00 · 610 阅读 · 0 评论 -
二分图最大权匹配算法模板
//最大权匹配bool sx[N],sy[N];int nx,ny,g[N][N],lx[N],ly[N],cx[N],cy[N];bool path(int u){//扩展二分图 判断是否存在由行元素u出发的可增广路径 int v; sx[u]=1; for(v=1;v if(g[u][v]==lx[u]+ly[v]&&!sy[v]){ sy[v]=1; if(cy[v]==0||path(cy[v])){原创 2010-11-09 22:21:00 · 645 阅读 · 0 评论 -
二分图匹配算法模板
//Hopcroft_Karp算法//en=0;//memset(head,-1,sizeof(head));int en,nx,ny,head[N],mx[N],my[N],dx[N],dy[N];struct edge{ int x,y,nxt;}e[E];void addedge(int x,int y){ e[en].x=x; e[en].y=y; e[en].nxt=head[x]; head[x]=en++;}bool bfs(int nx){ bool fi原创 2010-11-09 22:20:00 · 600 阅读 · 0 评论 -
最小费用流算法模板
//最小费用流//memset(head,-1,(n+2)*sizeof(int));//en=0;struct edge{ int x,y,f,c,nxt;}e[E];int en,head[N],pre[N],dist[N],visited[N];void add(int x,int y,int f,int c){ e[en].x=x; e[en].y=y; e[en].f=f; e[en].c=c; e[en].nxt=head[x]; head[x]=en+原创 2010-11-09 22:18:00 · 1031 阅读 · 0 评论 -
最大流算法模板
//最大流//memset(head,-1,sizeof(head));//en=0;struct edge{ int x,y,c,nxt;}e[E];bool del[V];int head[V],d[V],q[V],stk[V],pre[V],en,src,dest;void addedge(int x,int y,int c){ e[en].x=x; e[en].y=y; e[en].c=c; e[en].nxt=head[x]; head[x]=en++;原创 2010-11-09 22:17:00 · 647 阅读 · 0 评论 -
TSP问题之动态规划解法
这几天在想办法求解TSP问题,众所周知,TSP问题是NP难问题,现在我们用动态规划来求解之。 其实这个可以转化为一个填表问题。其中一步是求解集合的所有子集合,整个问题还没完,等我哪天有时间了,把他详细写出来。把求子集合的代码先贴在这里。 #include#define N 100bool b[N];int n,a[N];void set_combinatio原创 2012-10-29 22:58:10 · 4249 阅读 · 0 评论