2014年7月17日
摘要: 01背包,DP简答题就行,要用滚动数组,不然内存要爆。for循环的方向很重要,虽然是简单题,但对理解DP帮助很大,听队长说要把每一个状态写出来,我试着写了一下,果然更容易理解了。 1 #include 2 #include 3 #define doumax(a,b) (a>b?a:b) 4 cons... 阅读全文
posted @ 2014-07-17 19:47 BMESwimming 阅读(116) 评论(0) 推荐(0) 编辑
摘要: DP简单题,以前用for循环写过,这次用状态递归写。感觉确实思路比以往清晰许多。 1 #include 2 #include 3 const int maxm=500+5,maxn=1000+5; 4 int d[maxm][maxn],a[maxm][maxn],n; 5 int trimax(i... 阅读全文
posted @ 2014-07-17 19:43 BMESwimming 阅读(304) 评论(0) 推荐(0) 编辑
摘要: DFS题,类似八皇后问题,题目有点长,看了老半天才看懂。特别是上下左右数字要注意。还要注意剪枝,另外空行不能多输,输多了不能AC(运行速度有点慢,能AC但1940ms,估计还有待优化) 1 #include 2 #include 3 const int maxn=25+5; 4 int num[ma... 阅读全文
posted @ 2014-07-17 19:41 BMESwimming 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 油田问题,有点像图像处理里的区域生长问题,找油田块数。BFS,DFS都可以。 1 /*BFS*/ 2 #include 3 #include 4 const int maxn=100+5,maxm=1000; 5 int m,n,vis[maxn][maxn],mat[maxn][maxn],dir... 阅读全文
posted @ 2014-07-17 19:37 BMESwimming 阅读(182) 评论(0) 推荐(0) 编辑
摘要: BFS题,只是没有目标位置,只需记下走过的黑色的块数就行 1 #include 2 #include 3 const int maxn=1000,maxm=25; 4 int vis[maxm][maxm],mat[maxm][maxm],dir[5][3]={{1,0},{0,-1},{-1,0}... 阅读全文
posted @ 2014-07-17 19:33 BMESwimming 阅读(153) 评论(0) 推荐(0) 编辑
摘要: /*BFS,注意马脚!马脚WA了一次,后来WA了N次,最后发现输入时候将军和马的位置搞反,更改后AC*/1 #include 2 #include 3 #include 5 using namespace std; 6 const int maxn=10000,maxm=25; 7 int vis... 阅读全文
posted @ 2014-07-17 19:29 BMESwimming 阅读(220) 评论(0) 推荐(0) 编辑
摘要: BFS,最好先打个质数表。 1 #include 2 #include 3 #include 4 #include 5 //#include 6 const int maxn=15000+5; 7 int s[10]; 8 int vis[maxn],isp[maxn]; 9 us... 阅读全文
posted @ 2014-07-17 19:21 BMESwimming 阅读(424) 评论(0) 推荐(0) 编辑
摘要: BFS结合队列#include#include#includeusing namespace std;int x,y,l;const int maxn=300+5;int visit[maxn][maxn];struct node{ int xpos; int ypos; int ... 阅读全文
posted @ 2014-07-17 19:17 BMESwimming 阅读(168) 评论(0) 推荐(0) 编辑