日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客网暑期ACM多校训练营(第三场)A - PAXM Team(01背包)

發(fā)布時間:2024/4/18 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客网暑期ACM多校训练营(第三场)A - PAXM Team(01背包) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目鏈接

思路

多重限制條件的01背包,輸出選取那幾小組,可以開個bool數(shù)組記錄選取物品時的狀態(tài),然后從最后一個物品往上找標記。

后記

這道題比賽的時候數(shù)據(jù)太水,簡單排序選一件物品就行,看別人代碼還有直接輸出零過了。。。比賽結(jié)束1小時左右,加強數(shù)據(jù)了,還好提前過了 ^ _ ^
物品標記當時想錯了,賽后看看學長代碼真的強

#include <iostream> #include <algorithm> #include <stdio.h> #include <vector> #include <map> #include <bitset> #include <set> #include <string.h> #include <cmath> #include <queue> #include <algorithm> #define N 40 #define ll long long #define lowbit(a) a&(-a) #define pb(a) push_back(a) #define mk(a, b) make_pair(a, b) #define mem(a, b) memset(a, b, sizeof(a)) #define read(a) scanf("%d", &a) #define print(a) printf("%d\n", a) using namespace std; struct group{int p, a, c, m, g; }a[N]; // 也可以開4個數(shù)組存每個小組信息,因為沒有問最大的分值 int dp[N][N][N][N]; bool vis[N][N][N][N][N]; int main(){#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin); #endifint n, P, A, M, C, G;scanf("%d", &n);for (int i = 0; i < n; ++i) {scanf("%d%d%d%d%d", &a[i].p, &a[i].a, &a[i].c, &a[i].m, &a[i].g);}scanf("%d%d%d%d", &P, &A, &C, &M);for (int i = 0; i < n; ++i) {for (int j = P; j >= a[i].p; --j) {for (int k = A; k >= a[i].a; --k) {for (int l = C; l >= a[i].c; --l) {for (int r = M; r >= a[i].m; --r) {if (dp[j - a[i].p][k - a[i].a][l - a[i].c][r - a[i].m] + a[i].g > dp[j][k][l][r]) {dp[j][k][l][r] = dp[j - a[i].p][k - a[i].a][l - a[i].c][r - a[i].m] + a[i].g;// 將當前狀態(tài)標記vis[i][j][k][l][r] = true;}}}}}}vector<int> wu;// 從最后一個物品向前找標記for (int i = n - 1, j = P, k = A, l = C, r = M; i >= 0; --i) {if (vis[i][j][k][l][r]) {wu.push_back(i);j -= a[i].p;k -= a[i].a;l -= a[i].c;r -= a[i].m;}if (j < 0 || k < 0 || l < 0 || r < 0)break;}if (wu.empty()) {printf("%d\n", 0);}else {printf("%d\n", wu.size());sort(wu.begin(), wu.end());for (auto it : wu) {printf("%d ", it);}printf("\n");}return 0; }

總結(jié)

以上是生活随笔為你收集整理的牛客网暑期ACM多校训练营(第三场)A - PAXM Team(01背包)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。