摘要: The max_size() function returns the maximum number of elements that the container can hold. The max_size() function should not be confused with the size or capacity functions, which return the number of elements currently in the container and the the number of elements that the container will be a.. 阅读全文
posted @ 2013-08-30 18:17 xuefenhu 阅读(399) 评论(0) 推荐(0) 编辑
摘要: #include #include usingnamespace std; vector vec; constint a[4] = {1, 2, 5, 10}; //1,2,5,10四个基数任意次数组合相加得到一个数N,求所有可能组合。 //回溯,背包问题 void backup(int N)//总共k个数,和为N { if (N == 0) { vector::iterator it = vec.begin(); for (; it != vec.end(); ++it) cout= vec.back())// 非降序,为了去掉重复的组合 { vec.push_bac... 阅读全文
posted @ 2013-08-30 18:16 xuefenhu 阅读(647) 评论(0) 推荐(0) 编辑
摘要: 1 vector构造函数:也就是如何对一个vector对象进行初始化 ////////////////////////////代码////////////////////////////////////// explicit vector ( const Allocator& = Allocator() ); explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() ); template vector ( InputIterator first, InputIt 阅读全文
posted @ 2013-08-30 18:14 xuefenhu 阅读(636) 评论(0) 推荐(0) 编辑
摘要: 所谓回文字符串,就是一个字符串,从左到右读和从右到左读是完全一样的。比如"level" 、 “aaabbaaa”题目:判断一个字符串是否为回文解法:递归递归的作用在于把问题的规模不断缩少,直到问题缩少到能简单地解决问:如何缩少问题规模?答:通过观察可以知道,一个回文字符串其中内部也是回文。所以,我们只需要以去掉两端的字符的形式一层层检查,每一次的检查都去掉了两个字符,这样就达到了缩少问题规模的目的。新问题与原问题有着相同的形式当去掉两端字符后的字符串,其产生的新问题同样是检查这个字符串是否回文。递归的结束需要简单情景1. 字符串长度可能会奇数或偶数:如果字符串长度是奇数,字 阅读全文
posted @ 2013-08-30 11:16 xuefenhu 阅读(2359) 评论(0) 推荐(0) 编辑