上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 30 下一页
摘要: #include <iostream>#include <cstdio>#include <string>using namespace std;#define X 305string s;int map[X][X],color[X],n,x,y,len,c,ans;bool check(int a,int col) //检查顶点a的颜色能否涂成col{ for(int i=1;i<=n;i++) if(map[a][i]&&color[i]==col) //相邻节点颜色与他一样,不行 return false; return true 阅读全文
posted @ 2012-03-20 14:41 yejinru 阅读(220) 评论(0) 推荐(0) 编辑
摘要: 编辑器加载中.../*题目: 问周游一圈后能不能换钱得到利润分析: 有向图是否处在负环问题,因为涉及每个顶点都可能存在负环, 直接用flord算法做即可*/#include <iostream>#include <string>#include <cstring>using namespace std;#define X 35string city[X],s1,s2;double map[X][X];int main(){ freopen("sum.in","r",stdin); freopen("sum.o 阅读全文
posted @ 2012-03-20 14:40 yejinru 阅读(179) 评论(0) 推荐(0) 编辑
摘要: /*题目: 象棋中马如何走到指定地点分析: BFS题,分8个方向搜就行 具体的图型可以看看poj1915题的8个方向,理解BFS后很容易写出*/#include <iostream>#include <cstring>#include <queue>#include <cstdio>using namespace std;#define X 310int sx,sy,ex,ey,n;bool visit[X][X];struct node{ int x,y,step;};bool check(int x,int y){ if(x<1||y& 阅读全文
posted @ 2012-03-20 14:35 yejinru 阅读(153) 评论(0) 推荐(0) 编辑
摘要: 此方法是看了别人的题解的,利用像dp的思维做,f[m][n] = f[m][n-1]+f[m-n][n],其中f[m][n]表示m个水果n个盘子时总的放的方法数,因为f[m][n]总可以通过有空盘子或者没空盘子来放,f[m][n-1]表示有空盘子的情况,而f[m-n][n]表示没有空盘子的情况,思路非常巧妙#include <iostream>using namespace std;int ans;int dfs(int m,int n){ if(m==1) return 1; if(m<0) return 0; if(n==1) return 1; return dfs(m 阅读全文
posted @ 2012-03-20 14:33 yejinru 阅读(152) 评论(0) 推荐(0) 编辑
摘要: /*题目: 填充数独游戏分析: 先从后面开始搜,也就是从第八十个开始搜 1、如果一个小的方格内已经包含了非零的数,则继续向下搜 2、如果一个小的方格内是一个零数,也就是还没有放入相应的数,则对其从零到九开始尝试 3、对每一个数的尝试,检查其合法性:在其所在的3*3方格内是否合适;在此行是否合适,在此列是否合适 4、如果经过以上条件可以的话那么这个数字就可以放在此小方格上,然后继续进行搜索。*/#include <iostream>#include <cstring>#include <string>using namespace std;int a[10][ 阅读全文
posted @ 2012-03-20 14:28 yejinru 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 终于靠自己A了一道比较难的题了(n_n)据说是减枝题,不过我的剪枝还有待提高,以下做法竟然差点time limitted(985MS)我自己的思路:DFS搜索题,按当前需要构造的分数值,当前分母的总乘积,已经有了的个数,上一层分母值进行搜索,当遇到已经有了的个数等于a时,返回假,否则从上一层的分母值开始为下一个分数进行检查是否满足条件,满足的话答案加一#include <iostream>#include <cmath>using namespace std;#define X 1e-8int p,q,a,n;int ans;bool dfs(double cs,int 阅读全文
posted @ 2012-03-20 14:27 yejinru 阅读(286) 评论(0) 推荐(0) 编辑
摘要: 周赛的题目,思想011111111111000111111111111111转换为011111122222000333111444222555然后按该位置的高度向两边扩展,当遇到小于该高度时,停止扩展,然后用右边的下标减左边的下标加一,再乘以当前的高度即为所求,dp的实现是在计算第二个矩阵时用到的,只是简单的h[i,j] = h[i-1,j]+1 (map[i][j]=='F')#include <cstring>#include <iostream>#include <string>using namespace std;#define X 阅读全文
posted @ 2012-03-19 15:28 yejinru 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 输入括号输入:(注意:据说有空行,用getline()或者gets()输入)([(]([(((])))[]]]]])))(((要求输出最小要加入的括号数目之后的匹配括号串分析: 经典dp题,如果用dp自底向上的递推做的话,比较麻烦,其实用记忆化做很简单, 每次递归前加上判断是否已经计算过即可减少计算量,相当于dfs里的剪枝,代码如下#include <iostream>#include <string>#include <cstring>using namespace std;#define X 205#define INF 1000int dp[X][X] 阅读全文
posted @ 2012-03-19 11:13 yejinru 阅读(156) 评论(0) 推荐(1) 编辑
摘要: 此题跟之前的括号最小添加数目一样的做法,只不过某些地方稍加改动,可以看看前一篇的括号最小添加数#include <iostream>#include <string>#include <cstring>using namespace std;#define X 210#define INF 1000string s;int dp[X][X];int f(int i,int j) //记忆化dp{ if(dp[i][j]!=-1) //如果已经算过,直接结束 return dp[i][j]; else if(i>=j) return 0; int ans 阅读全文
posted @ 2012-03-19 08:56 yejinru 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 题目:输入括号输入:(注意有空行,用getline()或者gets()输入)([(]([(((])))[]]]]])))(((要求输出最小要加入的括号数目分析: 经典dp题,如果用dp自底向上的递推做的话,比较麻烦,其实用记忆化做很简单, 每次递归前加上判断是否已经计算过即可减少计算量,相当于dfs里的剪枝,代码如下#include <iostream>#include <string>#include <cstring>using namespace std;#define X 205#define INF 1000int dp[X][X];string 阅读全文
posted @ 2012-03-19 08:32 yejinru 阅读(298) 评论(0) 推荐(0) 编辑
上一页 1 ··· 20 21 22 23 24 25 26 27 28 ··· 30 下一页