POJ 1416 DFS】的更多相关文章

题目翻译: 公司现在要发明一种新的碎纸机,要求新的碎纸机能够把纸条上的数字切成最接近而不超过target值.比如,target的值是50,而纸条上的数字是12346,应该把数字切成四部分,分别是1.2.34.6.因为这样所得到的和43 (= 1 + 2 + 34 + 6) 是所有可能中最接近而不超过50的.(比如1, 23, 4, 和6 就不可以,因为它们的和不如43接近50,而12, 34, 6也不可以,因为它们的和超过50了.碎纸还有以下三个要求: 1.如果target的值等于纸条上的值,则…
题目传送门:http://poj.org/problem?id=1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6860   Accepted: 3710 Description You have just been put in charge of developing a new shredder for the Shredding Company Although a "…
POJ 1416 Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5231   Accepted: 2964 Description You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would…
我的dfs真的好虚啊……,又是看的别人的博客做的 题目== 题目:http://poj.org/problem?id=1416 题意:给你两个数n,m;n表示最大数,m则是需要切割的数. 切割m,使得切割之后的数的和小于等于n. 求出最大的切割方法: 例: 50 12346 12346可以切割为 1 2 34 6和为43,这个数小于n. 12346也可以切割为1 2 3 4 6和为16,这个数也小于n: 但是43大于16,所以去43而不取16: 参考博客:http://www.cnblogs.c…
Shredding Company Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6173   Accepted: 3361 Description You have just been put in charge of developing a new shredder for the Shredding Company Although a "normal" shredder would just shre…
1.链接地址: http://poj.org/problem?id=1416 http://bailian.openjudge.cn/practice/2803 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 你现在负责设计一种新式的碎纸机.一般的碎纸机会把纸切成小片,变得难以阅读.而你设计的新式的碎纸机有以下的特点: 1.每次切割之前,先要给定碎纸机一个目标数,而且在每张被送入碎纸机的纸片上也需要包含一个数.2.碎纸机切出的每个纸片上都包括一个数.3.要求切出的每个纸…
题目: http://poj.org/problem?id=1416 又16ms 1A了,这人品... #include <stdio.h> #include <string.h> int n, ans; bool rejected; ], tmp[], ans_path[]; void dfs(int sum, char s[]) { if(sum > n)return; ] == '\0') { ; else if(sum > ans && sum…
题意:POJ少见的中文题,福利啊. 思路: 一开始也没有思路呃呃呃 . 裸搜,连样例都过不去...参照了网上的题解:一行一行DFS 茅塞顿开啊. #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; char a[9][9]; bool vis[9]; int ans,n,m; void stmd(int row,i…
  fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream> #include<string> #include<algorithm> #include<iterator> #include<sstream>//istringstream #include<cstring> #include<que…
F - (例题)不等式放缩 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1190 Description 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱.当i < M时,要求Ri &…
http://poj.org/problem?id=1562 #include<iostream> using namespace std; ,m=,sum=; ][]; ][]={-,, ,, ,-, ,, ,, -,-, -,, ,- }; void dfs(int a,int b) { if(!aa[a][b])return; aa[a][b]=; ;i<;i++) { ]; ]; &&a1<m&&b1>=&&b1<…
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace std; ,h=,sum=; ][]; void DFS(int p,int q) { &&p<h&&q>=&&q<n) { sum++; aa[p][q]='#'; } else return ; DFS(p-,q); DFS(p+,q);…
题目;http://poj.org/problem?id=1088 感觉对深搜还不太熟练,所以练习一下,类似于连连看的那题,注意的是所求的是最大达长度,并不是从最大的或者最小的点出发得到的就是最长的路径 #include<iostream> using namespace std; ,,,-}; ,-,,}; ][]; ][]; void dfs(int x,int y) { ;i<;i++) { int sx=x+dx[i]; int sy=y+dy[i]; ||sx>n||sy…
http://poj.org/problem?id=1562                                                                                                    Oil Deposits Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12595   Accepted: 6868 Description The GeoSurv…
题目链接:http://poj.org/problem?id=3414 题意:三个值A, B, C, A和B是两个杯子的容量,问最短操作数使A或者B里的水量是C.有三种操作. 思路:dfs.暴力 很简单.唯一不同的大概是这次做搜索都是自己想方设法的代码实现.中途很多问题.求得不是最大值.怎么保存操作过程.但好像不是原创方法. 附AC代码: // dfs 开始觉得一定是bfs 我只要把两个杯子的各种操作遍历一遍 直到某个杯子里的水和C相等就结束. // 然后想到的是如何分开这两个杯子.因为一次操作…
题目链接:http://poj.org/problem?id=2531 思路:由于N才20,可以dfs爆搞,枚举所有的情况,复杂度为2^(n). #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ][]; ]; int n,ans; void dfs(int pos,int sum) { ){ ans=max(ans,s…
题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ][]; ]; ]; int n,ans; bool Judge(int x,i…
Apple Tree Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30636   Accepted: 9162 Description There is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. Kaka likes apple very much, so he has been…
题目链接:http://poj.org/problem?id=1270 思路:就是一简单的dfs+拓扑排序,然后就是按字典序输出所有的情况. http://paste.ubuntu.com/5987294/…
POJ3009 DFS+剪枝 原题: Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16280 Accepted: 6725 Description On Planet MM-21, after their Olympic games this year, curling is getting popular. But the rules are somewhat different from our…
http://poj.org/problem?id=2631 2333水题, 有一个小技巧是说随便找一个点作为起点, 找到这个点的最远点, 以这个最远点为起点, 再次找到的最远点就是这个图的最远点 证明可以用三角形定理 #include<iostream> #include<cstdio> #include<vector> #include<cstring> #define maxn 10005 using namespace std; struct don…
点击打开链接 题目大意是有一个分割机,可以把一串数字分割成若干个数字之后求和,题目输入一个数字上界和待分割的数字,让我们求出分割后数字之和在不超过给定max的情况下的最大值,并且给出分割方案,如果没有分割方案,则输出error,如果有多种方案则输出rejected. 这是个搜索题,深搜就可以求解,但是有一些剪枝的方案,题目讨论区说貌似不剪枝也能过,没试过,我一开始就写了有剪枝的,下面说一下一些剪枝方案: 假设题目输入格式为max number 1,如果number各个位相加以后仍然大于max,则…
单点修改树中某个节点,查询子树的性质.DFS序 子树序列一定在父节点的DFS序列之内,所以可以用线段树维护. 1: /* 2: DFS序 +线段树 3: */ 4:   5: #include <cstdio> 6: #include <cstring> 7: #include <cctype> 8: #include <algorithm> 9: #include <vector> 10: #include <iostream> 1…
Description Building and maintaining roads among communities in the far North is an expensive business. With this in mind, the roads are build such that there is only one route from a village to a village that does not pass through some other village…
Hopscotch Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2845   Accepted: 1995 Description The cows play the child's game of hopscotch in a non-traditional way. Instead of a linear set of numbered boxes into which to hop, the cows creat…
Language: Default Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12367   Accepted: 6325 Description When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that ever…
枚举行和列即可,当前已经放下cnt个棋子,当前已经搜索到第r行,如果 n - r + cnt  < k 直接退出,因为后面无法放下剩下的棋子. AC代码 #include<cstdio> #include<cstring> const int maxn = 10; char G[maxn][maxn]; int vis[maxn], n, k; int ans; void dfs(int x, int cnt){ if(cnt == k){ ans++; return; }…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1539 大意是输入n和m,把m按顺序拆分成若干个数,问这些数和的在小于n的前提下最大为多少 注意必须m的每一位都不能漏,而且要按顺序拆 比如第一个例子 拆成的各个数为1,2,34 和6,可以拆成34,346但不能是36或364,要按顺序 而他们和的最大是43 如果找不出拆法能使各个数的和小于n,输出error 如果有不止一种拆法子,输出 rejected 0 0的时候结束 m最多为六位数 这道题在杭电…
DES:给一个n行m列的棋盘.马以L型走.问能否从某一位置开始走完棋盘上的每个位置.若能继续输出字典序最小的一条路径. 很典型的dfs.搜的时候就按照字典序从小到大的顺序.搜到第一条路径时停止搜索输出路经就好了.感觉dfs很机智.WA了几次都是因为保存答案那里没有回溯..........一开始还以为没搞清楚行和列哪个是用字母表示的.....T_T ....读题很难的..... A Knight's Journey #include<stdio.h> #include<iostream&g…
                                                                                                                                                                                                   Flip Game Time Limit: 1000MS   Memory Limit: 65536K Tot…