@Rohlff · 2019年4月7日 动态规划 0-1背包 问题描述:给定n个以(w,v)表示的物品,其中w代表重量,v代表价值;此外,给定一个背包的总重量W. 问:能获得的最大价值为几何? 解:对于每个物品v,可以选择选或者不选。只要比较一下选和不选哪个带来的价值更高即可。 if w[i]>背包承 ...
@Rohlff · 2019年4月6日 C++/String Trim()和去掉字符串中所有空格 #include <iostream> #include <string> using namespace std; //去除首尾空格,类比于Java的trim() void trim(string &s){ if(s.empty()) return ; s.erase(0,s.find_first_not_of(' ')); s.er ...
@Rohlff · 2019年3月28日 快排 #include <iostream> #include <algorithm> #include <vector> using namespace std; void quick_sort(vector<int> &v,int low,int high){ int i=low; int j=high; if(i>=j) return; int base = v[low]; while (i<j) { ...