两张表各占多少格
三件物品、容量 10。二维表是 (件数+1) × (容量+1),一维表就是 容量+1。运行下面这段程序:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using Item = pair<int, int>; // (重量, 价值)
const vector<Item> ITEMS = {{3, 8}, {4, 9}, {5, 11}};
int main() {
int cap = 10;
int two = (ITEMS.size() + 1) * (cap + 1);
int one = cap + 1;
cout << two << "/" << one << endl;
}
(本题用 g++ -std=c++17 -O0 编译。)
全部评论