动态规划的一道题目,按照紫书的思路,先将书按照高度进行排序,然后依次向各层放置,进行相应的更新,并且进行计算得出最后的结果即可,具体实现见如下代码:
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
using namespace std;
int Case;
int N;
struct Book{
int h, w;
};
bool compare(const Book a, const Book b){
if (a.h != b.h) return a.h > b.h;
return a.w > b.w;
}
int dp[2][2110][2110];
vector<Book> record;
int width[100];
void update(int &l, int r){
if (l<0 || l>r) l = r;
}
int getHeight(int ind,int h){
if (ind != 0) return 0;
return h;
}
int main(){
cin >> Case;
while (Case--){