LeeBlog

导航

2011年5月4日 #

HDU 1258 Sum It Up

摘要: 这题郁闷了,排序过不了,后来仔细想想不用排序, 于是果断删了,没想到删了再杭电能过,在北大不能过,真郁闷了这题是以简单DFS,在搜到时把结果存起来,然后再暴力搜索,看是否已存在这样的sum,最后一次性输出来就o了.先贴一神代码把.... 这个hdu poj 都能过( 这个算法非常好.以后对于组合问题都能这么干了 )#include<stdio.h>int t,n,num[20],flag,res[20];void DFS( int p,int s,int nu ){ if( s == t ) { flag = 1; for( int i = 0; i < nu; ++i ) 阅读全文

posted @ 2011-05-04 22:40 LeeBlog 阅读(212) 评论(0) 推荐(0) 编辑

HDU 1016 Prime Ring Problem DFS + 记忆化搜索

摘要: 说实话,这题真没做出来,思路有,但是有问题一直不能解决,后来别人提供的思路.不多说了....这题就是要求形成一个环,没两个相邻的数之和不能为素数,当然最后一个要考虑他跟第一个的关系,这里的DFS其实只要递归一个东西,而我递归的东西却一直不对,主要受变形课影响,其实递归的东西肯定是当前的数目,然后把当前的数存在数组里,以便下一次递归的时候可以跟这一次的数比较....#include<stdio.h>#include<string.h>int n,num[25],des[25];int gcd( int n ){ int f = 0; if( n == 2 || n == 阅读全文

posted @ 2011-05-04 20:04 LeeBlog 阅读(219) 评论(0) 推荐(0) 编辑

HDU 2072 单词数

摘要: 这里跟前面两个字符串处理差不多,http://www.cnblogs.com/Lvsi/archive/2011/05/03/2035640.htmlhttp://www.cnblogs.com/Lvsi/archive/2011/05/04/2036156.html#include<stdio.h>#include<string.h>int n;char str[10005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { if( str[i] == ' ' ) { ++i; cont 阅读全文

posted @ 2011-05-04 10:02 LeeBlog 阅读(361) 评论(0) 推荐(0) 编辑

HDU 1062 Text Reverse

摘要: 这题一水题 .... 据说可以用函数做 ( strtok) ,没用,没看懂,自己写了一个.. 水果,不过记住中间有很多空格要原样输出......还有把字符串分开后,在每个后面都得赋值ASCII为0额#include<stdio.h>#include<string.h>int n,c;char str[1005],ch[1005][1005];void sort( ){ int i = 0; while( str[i] ) { int j = 0; while( str[i] == ' ' ) ch[c][j++] = str[i++]; ch[c][j] 阅读全文

posted @ 2011-05-04 09:49 LeeBlog 阅读(356) 评论(0) 推荐(0) 编辑