http://acm.hdu.edu.cn/showproblem.php?pid=6772
题意:
n件物品,每种物品有一个种类ti
四个属性 ai , bi , ci , di
每个种类最多选一件物品,求 四个属性分别求和 再与100相加 最后 乘积
思路:
DFS 种类i物品数量不超过50 跳过没有的种类
(没过
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> #include <vector> #include <iterator> #include <utility> #include <sstream> #include <limits> #include <numeric> #include <functional> using namespace std; #define gc getchar() #define mem(a) memset(a,0,sizeof(a)) //#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef char ch; typedef double db; const double PI=acos(-1.0); const double eps=1e-6; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=100+10; const int N=2e5+10; const int mod=1e9+7; int Len = 51; struct item{ int a = 0; int b = 0; int c = 0; int d = 0; }s[N][N]; ll ans[N],nxt[N]; int main(){ int sum = 0; int T = 0; int n = 0 , k = 0; cin >> T; while(T--){ sum = 0; memset(ans , 0 , sizeof(ans)); cin >> n >> k; for (int i = 0;i<n;i++){ int t , q , w , e , r; cin >> t >> q >> w >> e >> r; s[t][ans[t]].a = q; s[t][ans[t]].b = w; s[t][ans[t]].c = e; s[t][ans[t]].d=r; ans[t]++; } int x=k+1; for(int i=k;i;i--){ nxt[i]=x; if(ans[i])x=i; } int p = 1; int a , b , c , d; a = b = c = d = 0; int s1 = 0; for(int i = 0;i < ans[p] || ans[p] == 0;i++) { if(k+1 == p) { ll s = (a+100)*(b+100)*(c+100)*(d+100); if(s > s1) { s1 = s; } return 0; } p += 1; a += s[p][i].a; b += s[p][i].b; c += s[p][i].c; d += s[p][i].d; } cout << sum; } }