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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

51NOD 2072 装箱问题 背包问题 01 背包 DP 动态规划

發布時間:2023/12/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 51NOD 2072 装箱问题 背包问题 01 背包 DP 动态规划 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

有一個箱子容量為 V(正整數,0<=V<=20000),同時有 n 個物品(0<n<=30),每個物品有一個體積(正整數)。

現在在 n 個物品中,任取若干個裝入箱內,使得箱子的剩余空間為最小。

?收起

輸入

輸入:一個整數v,表示箱子容量 一個整數n,表示有n個物品 接下來 n 個整數,分別表示這 n 個物品的各自體積

輸出

輸出:一個整數,表示箱子最小的剩余空間

輸入樣例

24 6 8 3 12 7 9 7

輸出樣例

0 #include<iostream> #include<queue> #include<algorithm> #include<set> #include<cmath> #include<vector> #include<map> #include<stack> #include<bitset> #include<cstdio> #include<cstring> //---------------------------------Sexy operation--------------------------//#define cini(n) scanf("%d",&n) #define cinl(n) scanf("%lld",&n) #define cinc(n) scanf("%c",&n) #define cins(s) scanf("%s",s) #define coui(n) printf("%d",n) #define couc(n) printf("%c",n) #define coul(n) printf("%lld",n) #define speed ios_base::sync_with_stdio(0) #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout) //-------------------------------Actual option------------------------------//#define Swap(a,b) a^=b^=a^=b #define Max(a,b) a>b?a:b #define Min(a,b) a<b?a:b #define mem(n,x) memset(n,x,sizeof(n)) #define mp(a,b) make_pair(a,b) //--------------------------------constant----------------------------------//#define INF 0x3f3f3f3f #define maxn 100005 #define esp 1e-9 using namespace std; typedef long long ll; typedef pair<int,int> PII; //------------------------------Dividing Line--------------------------------// int v,n; int a[maxn]; int dp[maxn]; int main() {cini(v),cini(n);for(int i=0; i<n; i++)cini(a[i]);for(int i=0; i<n; i++){for(int j=v;j>=a[i];j--){dp[j]=max(dp[j],dp[j-a[i]]+a[i]);}}cout<<v-dp[v]<<endl; }

?

總結

以上是生活随笔為你收集整理的51NOD 2072 装箱问题 背包问题 01 背包 DP 动态规划的全部內容,希望文章能夠幫你解決所遇到的問題。

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