这题的01背包的特点很容易看出来,但其实发现,这个题讲究加入时候的顺序。

于是,用贪心排序,如代码中所示,如果A在B前面造成的分数损失更小,则排在前面。。。其实这个我也是猜的。。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; int dp[1005][3005]; struct Problem{
int a,b,c;
}pro[1005]; bool cmp(Problem a,Problem b){
if(a.c*b.b<b.c*a.b) return true;
else if(a.b*a.c+(a.c+b.c)*b.b==b.b*b.c+(a.c+b.c)*a.b){
if(a.b>b.b) return true;
}
return false;
} int main(){
int T,n,t;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&t);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
scanf("%d%d%d",&pro[i].a,&pro[i].b,&pro[i].c);
}
sort(pro+1,pro+1+n,cmp);
for(int j=1;j<=n;j++){
for(int i=1;i<=t;i++){
dp[j][i]=max(dp[j][i],dp[j-1][i]);
if(i<pro[j].c) continue;
dp[j][i]=max(dp[j][i],dp[j-1][i-pro[j].c]+pro[j].a-pro[j].b*i);
}
}
int ans=dp[n][0];
for(int i=1;i<=t;i++){
ans=max(ans,dp[n][i]);
}
printf("%d\n",ans);
}
return 0;
}

  

最新文章

  1. TFS API:一、TFS 体系结构和概念
  2. centos 下pip 安装snappy 系列问题记录
  3. c++程序判断系统是Linux还是Windows
  4. JPA中的@MappedSuperclass
  5. HDU 3436--Queue-jumpers (树状数组 or Splay Tree)
  6. a foreign key constraint fails
  7. 【译】ASP.NET MVC 5 教程 - 11:Details 和 Delete 方法详解
  8. bzoj1061 志愿者招募
  9. jquery-1.11.1.js
  10. ●BZOJ 1042 [HAOI2008]硬币购物
  11. Gradle学习之闭包
  12. C++对象模型的那些事儿之六:成员函数调用方式
  13. Java小问题
  14. JNDI学习总结——Tomcat下使用C3P0配置JNDI数据源
  15. JS获取IOS版本号
  16. 第9章 应用层(4)_超文本传输协议HTTP
  17. LintCode——数字统计
  18. graphql 数据导入工具
  19. webpack的3个路径配置项: assetsRoot、assetsSubDirectory、assetsPublicPath
  20. Docker-CE-CentOS安装&amp;更新&amp;卸载

热门文章

  1. Akka源码分析-Remote-网络链接
  2. hastable 用法
  3. 关于GIT使用过程中遇到的问题
  4. &lt;assert.h&gt;
  5. 【转】Java 集合系列01之 总体框架
  6. [ USACO 2018 OPEN ] Out of Sorts (Gold)
  7. php域名授权实现方法
  8. Ajax——php基础知识(三)
  9. html5——语义标签
  10. 【技术累积】【点】【java】【30】代理模式