T000ny

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年5月4日

摘要: sizeof考虑“\0”,strlen不考虑“\0”#include<stdio.h>#include<iostream>#include<string.h>using namespace std;int main(){ enum m{a,b,c,d,e,f,g,h,i,j,k,l}; cout << sizeof(m) <<endl;//4 枚举类型类似于指针 cout << sizeof("\0\0\0") <<endl;//4 3个\0 + 末尾的\0 = 4 cout << 阅读全文
posted @ 2013-05-04 22:35 T000ny 阅读(231) 评论(0) 推荐(0) 编辑

摘要: 1使用动态规划,dp[i][j]存储:到第i个物品时,空间大小为j的情况下的最大价值转移方程是:dp[i][j] = max(dp[i-1][j],dp[i-1][j - weight[i]] + value[i])时间复杂度是O(NV),N为物品的个数,V为最大容量,空间复杂度为O(NV)#include<iostream>using namespace std;const int N = 5;const int volumn = 1000;int dp[N + 1][volumn + 1];const int value[N+1] = {0,8,10,4,5,5};//下标从1 阅读全文
posted @ 2013-05-04 17:40 T000ny 阅读(153) 评论(0) 推荐(0) 编辑

摘要: Dijkstra算法:1 Dijkstra算法解决带权图的单源最短路径问题,权值要不小于0。2 顶点集合S,保存已经找到的从源点s找到的顶点。3 顶点集合V,保存剩下的节点,最小优先队列Q,存储V中节点。4 使用最小优先队列,寻找下一个顶点距离最近的节点u,然后使用w(s,u)来松弛u的邻接点v。===================================================================View Code 1 //prev[],dist[],distance[][] 2 #include<iostream> 3 #include<st 阅读全文
posted @ 2013-05-04 16:44 T000ny 阅读(888) 评论(0) 推荐(0) 编辑

摘要: #include<cstdlib>#include<iostream>#include<vector>using namespace std;void print(const vector<int>& vec){ vector<int>::const_iterator iter = vec.begin(); for(; iter!=vec.end(); iter++) cout << *iter << " "; cout << endl;}void find_combin 阅读全文
posted @ 2013-05-04 14:28 T000ny 阅读(711) 评论(0) 推荐(0) 编辑

摘要: 1 #include<iostream> 2 using namespace std; 3 template<typename T>void print(T* a, int len) 4 { 5 if(a == NULL) 6 return; 7 for(int i = 0; i < len; i++) 8 cout << a[i] << " "; 9 cout << endl;10 }11 template<typename T>void swap(T* a, T* b)12 {13 T tmp 阅读全文
posted @ 2013-05-04 11:03 T000ny 阅读(826) 评论(0) 推荐(0) 编辑