上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页
摘要: http://poj.org/problem?id=2533最长上升子序列的两种算法(1) O(n^2) 1 #include 2 #include 3 4 const int N=10010; 5 int dp[N],a[N];//dp[i]表示0~i的最长上升子序列的长度 6 int n; 7 8 int main() 9 {10 int n;11 while(~scanf("%d",&n))12 {13 memset(dp,0,sizeof(dp));14 for (int i = 0; i a[j] && dp[j]+1... 阅读全文
posted @ 2014-03-05 17:06 N_ll 阅读(145) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1159最长公共子序列 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=1010; 6 char s1[N],s2[N]; 7 int dp[N][N]; 8 9 int main()10 {11 while(~scanf("%s%s",s1,s2))12 {13 int len1 = strlen(s1);14 int len2 = strlen(s2);15 ... 阅读全文
posted @ 2014-03-02 10:53 N_ll 阅读(137) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1003感觉自己的dp弱爆了。。以前做的都忘得差不多了,只能从最基础的再学一遍吧。。求最大连续子段和。要知道一个定理,即最大连续子段和中不可能包含负的子段和。对于序列(....i......j,j+1.....),如果sum(i,j) 2 #include 3 const int N=100010; 4 int a[N]; 5 int main() 6 { 7 int t,n,o = 0; 8 scanf("%d",&t); 9 while(t--)10 {11 ... 阅读全文
posted @ 2014-02-28 17:24 N_ll 阅读(148) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1811 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int N=200010; 7 vectorV[N]; 8 queueq; 9 char oper[N];10 int in[N],f[N];11 int a[N],b[N];12 int n,m,sum;13 void init()14 {15 sum = n;16 while(!q.empty()) q.pop();17 ... 阅读全文
posted @ 2014-02-28 14:04 N_ll 阅读(195) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2647#include #include #include #define LL long longusing namespace std;int head[10006],cnt=0;int val[10006];int in[10006];int n,m,num;queueq;struct node{ int u,v; int next;} edge[20010];void add(int u,int v){ edge[cnt].u = u; edge[cnt].v = v; ... 阅读全文
posted @ 2014-02-27 14:55 N_ll 阅读(197) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2094 1 #include 2 #include 3 #include 4 using namespace std; 5 const int N=1010; 6 int num = 0,in[N]; 7 string name[N]; 8 int get_nameid(string s) 9 {10 int i;11 for (i = 0; i = num)15 name[num++] = s;16 return i;17 }18 int main()19 {2... 阅读全文
posted @ 2014-02-27 14:52 N_ll 阅读(276) 评论(0) 推荐(0)
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1285 1 #include 2 #include 3 const int N=1001; 4 int p[N][N],in[N]; 5 int n,m; 6 void toposort() 7 { 8 for (int i = 1; i <= n; i++) 9 {10 for (int j = 1; j <= n; j++)11 {12 if(in[j]==0)13 {14 ... 阅读全文
posted @ 2014-02-27 14:49 N_ll 阅读(166) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=2049题意:有一个迷宫,迷宫中有墙、门和空地。有M道墙,每一道墙用(x,y,d,t)表示,(x,y)表示墙的起始坐标,(d=1,t)表示向上t个单位都是墙;(d=0,t)表示向右t个单位都是墙。有N扇门,用(x,y,d)表示,(x,y)表示门的起始坐标,d=1,表示向上一个单位都是门;d=0,表示向右一个单位都是门。给出Nemo的起始位置(f1,f2),问起点到(0,0)的最少要穿过的门。表示对搜索的题很晕。。看到题不知道该怎么存,看了别人的题解才懂点。。 1 #include 2 #include 3 #include 4 ... 阅读全文
posted @ 2014-02-24 20:59 N_ll 阅读(270) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1400题意:给出一个表达式可能含有多余的括号,去掉多余的括号,输出它的最简形式。思路:先将表达式转化成后缀式,因为后缀式不含括号,然后再转化成中缀式,并根据运算符的优先级添加括号。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 char ss[1010]; 8 int f(char ch) 9 { 10 if(ch=='(') 11 return 0; 12 else ... 阅读全文
posted @ 2014-02-23 21:05 N_ll 阅读(260) 评论(0) 推荐(0)
摘要: http://poj.org/problem?id=1778题意:有两个DVD,第一个DVD上有编号为1~n1的安装包,第二个DVD上有编号为n1+1~n1+n2的安装包,给出m组关系(a,b) 表示安装a之前必须先安装b。由于安装时每次只能插入一个DVD,问安装完所有的安装包,这两个DVD至少要交换插入多少次。ps:第一次插入算一次,最后一次拔出算一次。思路:两次拓扑排序,以先插入第一个DVD,进行拓扑排序,求出交换次数;以先插入第二个DVD,进行拓扑排序,求出交换次数。最后输出这两种交换次数的最小的值。 1 #include 2 #include 3 #include 4 using... 阅读全文
posted @ 2014-02-22 15:55 N_ll 阅读(371) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 21 下一页