zoukankan      html  css  js  c++  java
  • Codevs 1014(装箱问题)

    题目链接:传送门

    题目大意:给你一个背包体积大小为n,有m个物品,任选物品放入背包使背包剩余体积最少。

    题目思路:转换为01背包求解,物品体积和价值等价,问题要使剩余空间最少,就可以转换为价值最大

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <cstring>
    #include <stack>
    #include <cctype>
    #include <queue>
    #include <string>
    #include <vector>
    #include <set>
    #include <map>
    #include <climits>
    #define lson root<<1,l,mid
    #define rson root<<1|1,mid+1,r
    #define fi first
    #define se second
    #define ping(x,y) ((x-y)*(x-y))
    #define mst(x,y) memset(x,y,sizeof(x))
    #define mcp(x,y) memcpy(x,y,sizeof(y))
    using namespace std;
    #define gamma 0.5772156649015328606065120
    #define MOD 1000000007
    #define inf 0x3f3f3f3f
    #define N 1000005
    #define maxn 100005
    typedef pair<int,int> PII;
    typedef long long LL;
    
    int n,m,ans;
    int a[50];
    int dp[20005];
    
    int main(){
        int i,j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;++i)scanf("%d",&a[i]); for(i=1;i<=m;++i){ for(j=n;j>=a[i];--j) dp[j]=max(dp[j],dp[j-a[i]]+a[i]); } printf("%d ",n-dp[n]); return 0; }
  • 相关阅读:
    交换实验
    路由引入和控制
    ISIS
    BGP联盟
    BGP2
    bgp
    Linux日常总结
    配置本地yum源方法
    达梦数据库常见问题-安装
    达梦数据库常见问题-安装
  • 原文地址:https://www.cnblogs.com/Kurokey/p/5659964.html
Copyright © 2011-2022 走看看