首页 > 其他 > 详细

01-背包 P2663 越越的组队

时间:2019-11-29 18:10:27      阅读:48      评论:0      收藏:0      [点我收藏+]

P2663 越越的组队

题解

是这题数据水还是。。。(数据怎么知道我人数有没有超一半啊)

f[ i ][ j ] 前 i 件物品中分数不超过 j 的最大分数

 

j 记录分数。。。

 

然后降一维01背包求解

 

 

代码

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>

using namespace std;

typedef long long ll;

inline int read()
{
    int ans=0;
    char last= ,ch=getchar();
    while(ch<0||ch>9) last=ch,ch=getchar();
    while(ch>=0&&ch<=9) ans=ans*10+ch-0,ch=getchar();
    if(last==-) ans=-ans;
    return ans;
}

int n;
int s[105];
int f[5005];
int ave=0,ans=0;

int main()
{
    n=read();
    for(int i=1;i<=n;i++) s[i]=read(),ave+=s[i];
    ave=ave/2;
    for(int i=1;i<=n;i++)
       for(int j=ave;j>=s[i];j--){
               f[j]=max(f[j],f[j-s[i]]+s[i]);
           ans=max(ans,f[j]);
       }
    printf("%d\n",ans);
    
    return  0;
}

 

01-背包 P2663 越越的组队

原文:https://www.cnblogs.com/xiaoyezi-wink/p/11959216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!