- 博客(16)
- 资源 (2)
- 收藏
- 关注
原创 动态规划0-1背包
#include #include using namespace std; //0-1背包问题,n种物品和一背包,物体i的重量是w[i],其价值为v[i],背包容量c。 //m(i,j)是背包容量为j,可选物品为1,...,i时的背包问题的最优值,用m[][]来存储m(i,j)的相应值 ,m[n+1][c+1] //template void Knapsack(int v[],int
2012-05-29 21:33:49
258
转载 c 语言 二维数组的函数参数传递的问题
二维数组的函数参数传递的问题,以前解决过好几次,总还是忘记,这回总结出来写在这里。 #include void print_a(int a[][5], int n, int m) { int i, j; for(i = 0; i { for(j = 0; j printf("%d ", a[i][j]); printf("\n"); } } vo
2012-05-29 15:15:50
311
原创 n后问题
// nQueen.cpp : 定义控制台应用程序的入口点。 #include "stdafx.h" #include using namespace std; class Queen { friend int nQueen(); public: bool Place(int k); void Backtrack(void); int n;//皇后的个数 int
2012-05-27 21:46:52
296
原创 资源分配动态规划
// ResourceAlloc.cpp : 定义控制台应用程序的入口点。 // //#include "stdafx.h" #include using namespace std; //输入:资源份额m,工程数n,各个工程对应的利润函数表p[n][m+1]; //f[n][m+1]记录前i个工程分配到不同份额资源时可获得的最大利润;数组d[n][m+1]记录f[i][x]最大时,
2012-05-27 21:25:41
944
原创 最大子段和问题的分治实现和动态实现
//最大子段和问题的分治算法 int MaxSubSum(int *a,int left,int right) { int sum=0; if (left==right) sum=a[left]>0?a[left]:0; else { int center=(left+right)/2; int leftsum=MaxSubSum(a,left,center);
2012-04-19 21:22:12
322
原创 动态规划 最长公共子序列
//头文件 //LCSLength //X[] 为X序列 Y[] 为Y序列 //c[i][j]存储Xi,Yj的最长公共子序列的长度 //b[i][j]记录c[i][j]的值是由哪一个子问题的截得到的 //c[i][j]= | 0; (i=0,j=0;) //c[i][j]= | c[i-1][j-1]; (x[i]=y[j]) b[i][j]=1 //c[i][j]= |
2012-04-19 19:13:01
229
原创 贪心算法最短路径
//头文件 #include const int maxint=101; template void Dijkstra(int n,int v,Type dist[],int prev[],Type (&c)[x][y]) {//单源最短路径的Dijkstra算法 bool s[maxint]; for (int i=1;i { dist[i]=c[v][i];
2012-04-17 19:57:01
635
转载 size_type 和 size_t 的区别
先是看到了在看标准库string时size_type,后来在学习标准库bitset的时候有碰到了size_t,晕啊 先说说是在什么样的机缘巧合下与size_type相遇的吧,O(∩_∩)O 标准库string里面有个函数size,用来返回字符串中的字符个数,具体用法如下: string st("The expense of spiritn"); cout 那么size()这个函数返
2012-04-15 20:37:31
364
转载 收集的关于C++中CString,int,string,char*,string之间的转换
string 转 CString CString.format("%s", string.c_str()); char 转 CString CString.format("%s", char*); char 转 string string s(char *); string 转 char * char *p = string.c_str(); str
2012-04-15 18:11:49
349
原创 哈希排序
#include "stdafx.h" #include using namespace std; typedef struct HashNode { int data; HashNode *next; } *HashList;//散列链表的每个结点的数据结构 inline void swap(int &i,int &j) { int temp=i; i=j;
2012-04-01 01:30:17
2419
原创 哈希查找
// HSearch.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include #define MAXSIZE 5 //#define 后面不加;他妹的我竟然忘了 using namespace std; typedef struct HashNode { int data; HashNode *next; } *HashL
2012-03-21 00:27:12
323
原创 c++ 数组参数小研究
#include using namespace std; void process_2d(int *a, int n, int m) { for (int i = 0; i for (int j = 0; j a[i*m+j] = 0; } template inline void process(in
2012-03-19 13:13:30
214
转载 MYSQL常用命令
MYSQL常用命令 1.导出整个数据库 mysqldump -u 用户名 -p --default-character-set=latin1 数据库名 > 导出的文件名(数据库默认编码是latin1) mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名
2012-03-17 10:58:46
171
原创 二分查找
#include using namespace std; template T bSearch(T a[],int n,T s) { int mid; int left=0; int right=n-1; while (left { mid=(left+right)/2; if (a[mid]==s) { return mid; }
2012-03-16 12:24:04
189
原创 合并排序
#include using namespace std; template void Merge(T B[],T C[],T A[],int m,int n) { int i=0,j=0,k=0; while (i { if (B[i] { A[k++]=B[i++]; } else { A[k++]=C[j++]; }
2012-03-16 12:20:47
197
原创 快速排序
#include using namespace std; int Partition(int A[], int l, int h) { int low=l,high=h; int pivotkey = A[l]; while (low { while (A[high] >= pivotkey&&high>l) --high; A[low] = A[h
2012-03-16 11:41:25
210
牛津实用英语语法.chm
2012-03-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人