[BJOI2019]排兵布阵

排兵布阵

题解

今天比赛上这道题好像是人均题呀。

好吧,就一个简单的,连优化都不需要的背包dp。

我们每次只需要处理在比第i个城堡的第j大的玩家大的情况,不必把所有的兵的情况都处理完。

然后就可以O\left(nms \right )过了。

源码

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL;
#define re register
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
int s,n,m;
int a
posted @ 2022-07-16 09:34  StaroForgin  阅读(13)  评论(0)    收藏  举报  来源