2011年5月11日

括号匹配 (转载)

摘要: 此文转自黑水浮云空间/*DP解法:F[i][j]表示到第i个位置的字符位置,有j-1个未被匹配的‘(’的状态有多少种,那么 f[i][j]=f[i-1][j-1] s[i]=‘(’; f[i][j]=f[i-][j+1] s[i]=‘)’;f[i][j]=f[i-1][j-1]+f[i-1][j+1] s[i]=‘?';最后输出f[len-1][1]即可,之所以j不直接从0开始(即最后输出f[len-1][0]),是为了避免转移方程中出现j=0,使得减1后小于0。*/#include <iostream> using namespace std; int f[20][20] 阅读全文

posted @ 2011-05-11 10:56 more think, more gains 阅读(174) 评论(0) 推荐(0) 编辑

括号匹配 强大的DFS

摘要: 轩载 神牛黑水浮云空间 #include<stdio.h>#include<string.h>char s[20];int sum,l;void work(int k,int cnt) /*cnt用来记录到当前k位置为止尚未被匹配的'(''的个数,如果出现负数直接 返回,如果到串尾并且cnt为0那么就是一种合法的状态,sum加1;否则继续DFS。*/{ if(k==l||cnt<0) {if(cn... 阅读全文

posted @ 2011-05-11 10:50 more think, more gains 阅读(189) 评论(0) 推荐(0) 编辑

tempter of the bone

摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>using namespace std;int N,M,T,flag,a,b,c,d;int xx[4]={0,0,1,-1};int yy[4]={1,-1,0,0};char map[30][30];int fun(int x,int y){ if(x<... 阅读全文

posted @ 2011-05-11 10:07 more think, more gains 阅读(139) 评论(0) 推荐(0) 编辑

Oil Deposits

摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>using namespace std;char map[21][21];int M,N,res;int xx[]={0,0,1,-1,-1,1,-1,1};int yy[]={1,-1,0,0,1,-1,-1,1};int fun(int x,int y)... 阅读全文

posted @ 2011-05-11 03:49 more think, more gains 阅读(115) 评论(0) 推荐(0) 编辑

Red and Black

摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>char map[21][21];int M,N,res;int xx[4]={0,0,1,-1};int yy[4]={1,-1,0,0};int fun(int x,int y){ if(x<0||y<0||x>=N||y>=M) return 0; return 1;}void DFS(... 阅读全文

posted @ 2011-05-11 03:19 more think, more gains 阅读(136) 评论(0) 推荐(0) 编辑

counting sheep

摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>int T,M,N;char map[110][110];int xx[4]={1,0,0,-1};int yy[4]={0,1,-1,0};int fun(int x,int y){ if(x<0||x>=N||y<0||y>=M) return 0; return 1;} void DFS... 阅读全文

posted @ 2011-05-11 03:06 more think, more gains 阅读(151) 评论(0) 推荐(0) 编辑

sum it up

摘要: #include<stdio.h>#include<string.h>#include<stdlib.h>int N,M,dp[50],mark[50],flag;void DFS(int x,int sum) //sum为和,x为当前数组标号{ int i,k,j,flag1=0; if(sum==N) { for(i=0;i<M;i++) { if(mark[i]==1) { if(!flag1) printf("%d",dp[i]),flag1=1; else printf("+%d",dp[i]); } 阅读全文

posted @ 2011-05-11 00:56 more think, more gains 阅读(181) 评论(0) 推荐(0) 编辑

导航