希望Total Smart和Totol Funess都尽量大,两者之间的关系是鱼和熊掌。这种矛盾和背包的容量和价值相似。

dp[第i只牛][j = 当前TotS] = 最大的TotF。

dp[i][j] = max(dp[i-1][j-s[i]])。

滚动数组根据j-s[i]和j大小关系决定递推顺序。

中间的j或者TF都可以为负,把j都加上下界的绝对值bound变成正数,最后再减掉就好。

对于s[i]和f[i]取值特殊的可以直接贪心

(1e8跑起来并不虚

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<string>
  4. #include<cstring>
  5. #include<queue>
  6. #include<vector>
  7. #include<stack>
  8. #include<vector>
  9. #include<map>
  10. #include<set>
  11. #include<algorithm>
  12. //#include<bits/stdc++.h>
  13. using namespace std;
  14.  
  15. const int maxn = 1e3+, maxs = 2e5, bound = 1e5;
  16. int s[maxn], f[maxn];
  17. int dp[maxs+];
  18.  
  19. //#define LOCAL
  20. int main()
  21. {
  22. #ifdef LOCAL
  23. freopen("in.txt","r",stdin);
  24. #endif
  25. int n, c = ; cin>>n;
  26. int TS = , TF = ;
  27. for(int i = n; i--;){
  28. scanf("%d%d",s+c,f+c);
  29. if(s[c]> && f[c]>){
  30. TS += s[c];
  31. TF += f[c];
  32. continue;
  33. }
  34. if(s[c]<= && f[c] <=) continue;
  35. c++;
  36. }
  37. memset(dp,0xc0,sizeof(dp));
  38. dp[bound] = ;
  39. for(int i = c; i--;){
  40. if(s[i]>){
  41. for(int j = maxs; j >= s[i]; j--){
  42. dp[j] = max(dp[j],dp[j-s[i]] + f[i]);
  43. }
  44. }
  45. else {
  46. for(int j = ; j-s[i] <= maxs; j++){
  47. dp[j] = max(dp[j],dp[j-s[i]] + f[i]);
  48. }
  49. }
  50. }
  51. int ans = bound;
  52. for(int i = bound; i <= maxs; i++){
  53. if(dp[i]+TF>=) ans = max(i+dp[i],ans);
  54. }
  55. printf("%d\n",ans-bound+TS+TF);
  56. return ;
  57. }

POJ 2184 Cow Exhibition(背包)的更多相关文章

  1. POJ 2184 Cow Exhibition【01背包+负数(经典)】

    POJ-2184 [题意]: 有n头牛,每头牛有自己的聪明值和幽默值,选出几头牛使得选出牛的聪明值总和大于0.幽默值总和大于0,求聪明值和幽默值总和相加最大为多少. [分析]:变种的01背包,可以把幽 ...

  2. [POJ 2184]--Cow Exhibition(0-1背包变形)

    题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  3. POJ 2184 Cow Exhibition (01背包变形)(或者搜索)

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10342   Accepted: 4048 D ...

  4. poj 2184 Cow Exhibition(01背包)

    Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10882   Accepted: 4309 D ...

  5. poj 2184 Cow Exhibition(dp之01背包变形)

    Description "Fat and docile, big and dumb, they look so stupid, they aren't much fun..." - ...

  6. POJ 2184 Cow Exhibition (01背包的变形)

    本文转载,出处:http://www.cnblogs.com/Findxiaoxun/articles/3398075.html 很巧妙的01背包升级.看完题目以后很明显有背包的感觉,然后就往背包上靠 ...

  7. poj 2184 Cow Exhibition(背包变形)

    这道题目和抢银行那个题目有点儿像,同样涉及到包和物品的转换. 我们将奶牛的两种属性中的一种当作价值,另一种当作花费.把总的价值当作包.然后对于每一头奶牛进行一次01背包的筛选操作就行了. 需要特别注意 ...

  8. POJ 2184 Cow Exhibition 01背包

    题意就是给出n对数 每对xi, yi 的值范围是-1000到1000 然后让你从中取若干对 使得sum(x[k]+y[k]) 最大并且非负   且 sum(x[k]) >= 0 sum(y[k] ...

  9. POJ 2184 Cow Exhibition (带负值的01背包)

    题意:给你N(N<=100)只牛,每只牛有一个智慧值Si和一个活泼值Fi,现在要从中找出一些来,使得这些牛智慧值总和S与活泼值总和F之和最大,且F和S均为正.Si和Fi范围在-1000到1000 ...

随机推荐

  1. 关于SqlDataReader使用的一点疑惑

    C#中的SqlDataReader类(System.Data.SqlClient)是用来在保持打开数据库连接的状态下取数据用的 用法如下图: “保持与数据库的连接”这个特性也是SqlDataReade ...

  2. centos 7 安装python3

    centos系统默认已安装python2.7,python3需要手动安装.以上是安装步骤 一.备份原来的2.7版本 首先看一下默认的python2.7在哪里 [root@apple ~]# cd / ...

  3. jsp页面将日期类型的数据转换成xxxx年xx月xx日xx时xx分

    <fmt:formatDate value="${bsjz.cxkssj}" pattern="yyyy"/><span class=&quo ...

  4. 模型事件注意点,before_delete、after_delete、before_write、after_write、before_update、after_update、before_insert、after_insert

    模型类支持before_delete.after_delete.before_write.after_write.before_update.after_update.before_insert.af ...

  5. jmeter将参数值写入到指定文件(转)

    有时在测试过程中需要将测试过程中生成的参数保存下来,jmeter并没有此类功能,此时,可以 通过beanshell编写代码来实现 思路: 每次请求响应返回后,通过正则表达式获取到需要保存的值,通过Be ...

  6. ubuntu设置nginx为系统服务

    ubuntu设置nginx为系统服务,如果没有设置为系统服务,无法执行 sudo service nginx startsudo service nginx stop 设置为系统服务命令 sudo u ...

  7. SQL Server 查看分区表(partition table)的分区范围(partition range)

    https://www.cnblogs.com/chuncn/archive/2009/02/20/1395165.html SQL Server 2005 的分区表(partition table) ...

  8. Linux Shell命令系列(1)

    1. ls命令ls命令是列出目录内容(List Directory Contents)的意思.运行它就是列出文件夹里的内容,可能是文件也可能是文件夹.“ls -l”命令以详情模式(long listi ...

  9. HiveSQLException: Error while compiling statement: No privilege 'Create' found for outputs { database:default }

    今天用Hive的JDBC实例时出现了HiveSQLException: Error while compiling statement: No privilege 'Create' found for ...

  10. Java学习笔记--继承和多态(上)

    1.通过继承来开发超类(superclass) 2.使用super 关键词唤起超类的构造方法 3.在超类中覆盖方法 4.区分override和overload 5.在Object类中探索toStrin ...