2013年7月2日
摘要: printfint a = 35;printf ("%03d", a);//将打印 035printf(“%-*s”, width, string); “*”: 在这里用width代替,其实和printf(“%-10s”, string) 一样,都是控制左对齐的,只是把“10”这个数字给参数化了。scanffscanf里面一般不写反斜杠n定义函数 int sscanf (const char *str,const char * format,........);函数说明 sscanf()会将参数str的字符串根据参数format字符串来转换并格式化数据。格式转换形式请参考. 阅读全文
posted @ 2013-07-02 23:01 wwjyt 阅读(390) 评论(0) 推荐(0)
  2013年6月30日
摘要: 对比前一篇 背包问题看。此篇特别注意的是 状态转移的范围 (与 状态转移的条件) line31 & 33以及 每一个状态的初值处理,并利用这个初值 处理递归最后一层的情况 line30 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 #define MAX 11010 #define INF -111 12 int height[MAX];13 int map[MAX];14 int N;15 stack s; 16 17 int max(int a, i... 阅读全文
posted @ 2013-06-30 22:00 wwjyt 阅读(458) 评论(0) 推荐(0)
摘要: 此类问题的重点是 "状态转移",比如当前背包容量为300,我可以拿10,拿20,拿30.所以 在当前状态下如果我拿10了,状态就转移到290(300-10);拿20了,状态就转移到280(300-20);拿30亦然.而每一个状态的int值 记录了该状态的 最大/小 的目的值.当然,状态的转移有一定的限制条件,只能转移到可以转移的状态.(比如当前背包容量20,就不能拿30的了)状态的转移也有一定范围#include #include #include #define MAX 100010#define INF -1int money, kind;int value[MAX], 阅读全文
posted @ 2013-06-30 17:11 wwjyt 阅读(354) 评论(0) 推荐(0)
  2013年6月28日
摘要: 一个由n行数字组成的三角形,第i行有2i-1个正整数(小于等于1000),如下:37 1 42 4 3 6 28 5 2 9 3 6 2要求你用笔从第1行画到第n(0 #include #include #define MAX 300 //开100不行了!#define INF -1int map[MAX][MAX];int in[MAX][MAX];int line;int m(int a, int b, int c){ return a>b?(a>c?a:c):(b>c?b:c);}int dp(int i, int j){ if(map[i][j] != INF) .. 阅读全文
posted @ 2013-06-28 21:10 wwjyt 阅读(267) 评论(0) 推荐(0)
摘要: #include #include #define INF -1#define MAX 1010int map[MAX][MAX];char a[MAX], b[MAX];int min(int a, int b, int c){ return a }int dif(int i, int j){ if( a[i-1] == b[j-1]) //注意图的第0行 or 第0列表示什么 算法概论P180图6-4 return 0; else return 1;}int dp(int i, int j){ if( map[i][j] != INF) ... 阅读全文
posted @ 2013-06-28 20:26 wwjyt 阅读(222) 评论(0) 推荐(0)
  2013年6月25日
摘要: 阅读全文
posted @ 2013-06-25 20:50 wwjyt 阅读(119) 评论(0) 推荐(0)
摘要: #include #include #include #include #include #include #include using namespace std;int r,c;int map[1010][1010];int time[1010][1010];int dir[4][2] = {{0,1},{1,0},{0,-1},{-1,0}};queue > J; //声明方式queue > F;void print(){ int i,j; for(i = 0; i FF; int t, i, x, y; while( !F.empty() ) { ... 阅读全文
posted @ 2013-06-25 09:50 wwjyt 阅读(218) 评论(0) 推荐(0)
  2013年6月24日
摘要: 1、简介 class pair ,中文译为对组,可以将两个值视为一个单元。对于map和multimap,就是用pairs来管理value/key的成对元素。任何函数需要回传两个值,也需要pair。 该函数的相关内容如下所示: |->Type----->struct |->Include---> |->Define----> pair(first,second) | |->member | |------>first | |------>second... 阅读全文
posted @ 2013-06-24 15:27 wwjyt 阅读(376) 评论(0) 推荐(0)
摘要: public class b2 { public static void main(String args[]) { int a[] = {9,1,2,3,5,0,7,8,4,6}; int max, min, i, j; /* for(max = min = a[0], i = 1; i max) max = a[i]; if(a[i] a[j]) { int temp = a... 阅读全文
posted @ 2013-06-24 14:40 wwjyt 阅读(152) 评论(0) 推荐(0)
  2013年5月7日
摘要: #include int count = 0;void dfs(int all,int step){ if(all>39) return; if(all==39 && step%2==0) { count++; return; } if(all<=37)dfs(all+2,step+1); if(all<=38)dfs(all+1,step+1);}int main(){ dfs(0,0); printf("%d\n",count);}//结果:51167078 阅读全文
posted @ 2013-05-07 20:33 wwjyt 阅读(129) 评论(0) 推荐(0)