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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

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

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

鏈接:https://www.nowcoder.com/acm/contest/141/A
來源:牛客網

題目描述

Eddy was a contestant participating in ACM ICPC contests. ACM is short for Algorithm, Coding, Math. Since in the ACM contest, the most important knowledge is about algorithm, followed by coding(implementation ability), then math. However, in the ACM ICPC World Finals 2018, Eddy failed to solve a physics equation, which pushed him away from a potential medal.

Since then on, Eddy found that physics is actually the most important thing in the contest. Thus, he wants to form a team to guide the following contestants to conquer the PACM contests(PACM is short for Physics, Algorithm, Coding, Math).

There are N candidate groups each composed of pi physics experts, ai algorithm experts, ci coding experts, mi math experts. For each group, Eddy can either invite all of them or none of them. If i-th team is invited, they will bring gi knowledge points which is calculated by Eddy's magic formula. Eddy believes that the higher the total knowledge points is, the better a team could place in a contest. But, Eddy doesn't want too many experts in the same area in the invited groups. Thus, the number of invited physics experts should not exceed P, and A for algorithm experts, C for coding experts, M for math experts.

Eddy is still busy in studying Physics. You come to help him to figure out which groups should be invited such that they doesn't exceed the constraint and will bring the most knowledge points in total. 示例1 2 1 0 2 1 10 1 0 2 1 21 1 0 2 1

輸出

1 1 示例2

輸入

1 2 1 1 0 31 1 0 2 1

輸出

0


題意按照我的理解就是相當于一個具有多個重量W的01背包。就是從一個W擴展到P,A,C,M四個屬性。
大概做法就是按照01背包的樣式進行改寫就可以了,因為范圍很小只有36,所以時間復雜度就是個五層的循環,大概O(pow(36,5)) = 6000w左右,不會超時,這里要降一層數組,
就是4層的一個dp數組就夠了。也不會超內存.使用記錄路徑的方法,直到最后再還原回去把加入的物品記錄下來最后再輸出。也就是一個很裸的做法。


#include <bits/stdc++.h>using namespace std;const int m=40;struct node{int P,A,C,M,G; }a[m];int A,B,C,D; int N; int dp[m][m][m][m]; bool path[m][m][m][m][m]={0};//用int超內存了int main() {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",&A,&B,&C,&D);for(int i=0;i<N;i++){for(int j=A;j>=a[i].P;j--){for(int k=B;k>=a[i].A;k--){for(int l=C;l>=a[i].C;l--){for(int o=D;o>=a[i].M;o--){if(dp[j][k][l][o]<dp[j-a[i].P][k-a[i].A][l-a[i].C][o-a[i].M]+a[i].G){dp[j][k][l][o]=dp[j-a[i].P][k-a[i].A][l-a[i].C][o-a[i].M]+a[i].G;path[i][j][k][l][o] = 1;}}}}}}vector<int> ans;for(int i=N-1; i>=0 && A>=0 && B>=0 && C >=0 && D>=0 ;i--) {if(path[i][A][B][C][D]) {ans.push_back(i);A -= a[i].P,B -= a[i].A;C -= a[i].C,D -= a[i].M;}}int sz = ans.size();printf("%d\n",sz);for(int i=0;i<sz;i++) {printf(i==sz-1?"%d\n":"%d ",ans[i]);}return 0; }

?

轉載于:https://www.cnblogs.com/Fy1999/p/9384061.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 在线观看日韩精品 | 福利在线一区二区三区 | 日本成人福利视频 | 精品www久久久久久奶水 | 97人人艹| 男女视频一区 | 精品人妻一区二区三区免费看 | 美女三级网站 | 中文字幕欧美激情 | 欧美极品videos精品 | 国产l精品国产亚洲区久久 午夜青青草 | 91久久精品在线 | 毛片毛多水多 | 啪啪在线观看 | 欧美裸体精品 | 国产成人免费视频网站 | 人妻精品无码一区二区 | 国产片网站| 亚洲欧美中日韩 | h视频在线观看网站 | 99久久人妻精品免费二区 | 性色av浪潮av | 色五丁香 | 少妇婷婷 | 国产欧美一区二区精品性色 | 97在线免费公开视频 | 国产婷婷色一区二区 | 欧美一级片网址 | 国产特级aaaaaa大片 | 中文文字幕一区二区三三 | 无码人妻黑人中文字幕 | 国产aa大片 | 三级黄色生活片 | 国产丝袜视频在线 | 亚洲国产一二三区 | 朝桐光在线视频 | av免费成人 | 久久伊人一区 | 国产白丝精品91爽爽久久 | av色综合| 国产精品精品国产 | 国产一区二区三区精品视频 | 美国成人免费视频 | 久久久久无码国产精品一区李宗瑞 | 亚洲加勒比在线 | 色香蕉视频 | 免费午夜网站 | 婷婷久久五月天 | 午夜久久一区 | 草久久| 99精品久久久久久久 | 可以免费看的黄色 | 香港一级淫片免费放 | 怡红院成人在线 | 亚洲欧美一区二区激情 | 国产福利一区二区 | 一个色av | 久久妇女 | 成人xx视频 | xxxxx18日本| 亚洲乱色熟女一区二区 | 国产二区视频在线观看 | 男人综合网 | 欧美午夜激情视频 | 欧美精品aa | 欧美在线视频网站 | 国产精品无码av在线有声小说 | 国产真实的和子乱拍在线观看 | 中文天堂资源在线 | 女仆裸体打屁屁羞羞免费 | 日日夜夜91| 69人人 | av无码精品一区二区三区 | 三级理论电影 | 欧美激情国产精品 | 嫩草av久久伊人妇女超级a | 日韩av手机在线 | 特黄aaaaaaaaa毛片免费视频 | 裸体美女免费视频网站 | 男人的天堂中文字幕 | 在线se | 国产校园春色 | 成人一级视频在线观看 | 亚洲AV成人无码精电影在线 | 日本男人天堂 | 欧美高清成人 | 韩国美女一区 | 欧美啊v| 香蕉黄视频 | 国产伊人精品 | 免费黄色在线网址 | 日韩欧美精品在线视频 | av天堂一区| 91亚洲精品久久久蜜桃网站 | 在线观看中文字幕码 | 国产一区二区视频免费 | 老司机性视频 | 大香依人 | 欧美91av|