SSL2764 2017年10月8日提高组T1 didi(dp)
来源:互联网 发布:python win32api 截屏 编辑:程序博客网 时间:2024/05/06 11:23
2017年10月8日提高组T1 didi
Description
Input
Output
分析:一看就是dp,排序之后做一次01背包就好了,按b[i]/c[i]从大到小排序。
代码
#include <cstdio>#include <algorithm>#define maxn 6000using namespace std;struct arr{ int a,b,c; double q;}s[maxn];int f[maxn],n,t;int so(arr u,arr v){ return u.q>v.q;}int fmax(int x,int y){ if (x>y) return x; return y;}int main(){ //freopen("didi.in","r",stdin); //freopen("didi.out","w",stdout); int T; scanf("%d",&T); for (int l=1;l<=T;l++) { scanf("%d%d",&n,&t); for (int i=1;i<=n;i++) { scanf("%d%d%d",&s[i].a,&s[i].b,&s[i].c); s[i].q=s[i].b*1.0/s[i].c*1.0; } sort(s+1,s+n+1,so); for (int i=1;i<=n;i++) for (int j=t;j>=s[i].c;j--) f[j]=fmax(f[j],f[j-s[i].c]-s[i].b*j+s[i].a); int ans=0; for (int i=1;i<=t;i++) if (f[i]>ans) ans=f[i]; printf("%d\n",ans); for (int i=1;i<=t;i++) f[i]=0; } fclose(stdin); fclose(stdout);}
阅读全文
0 0
- SSL2764 2017年10月8日提高组T1 didi(dp)
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- 2017年8月10日提高组T1 数学
- SSL2831 2017年11月3日提高组T1 跃动(dp)
- SSL2833 2017年11月3日提高组T1 Alice的疑问(数位dp)
- SSL2839 2017年11月6日提高组T1 游戏(dp)
- SSL2676 2017年8月10日提高组T1 数学(快速幂)
- 2017年8月8日提高组T1 作业
- 2017年8月8日提高组T1 作业
- 2017年8月8日提高组T1 作业
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 呵呵
- 2017年8月7日提高组T1 根
- 2017年8月9日提高组T1 水题
- 2017年8月9日提高组T1 水题
- 2017年8月14日提高组T1 跳跃
- bn层
- hankson的趣味题
- 面向对象vs面向过程
- Codeforces- Balanced Substring (思维)
- xmake-vscode插件开发过程记录
- SSL2764 2017年10月8日提高组T1 didi(dp)
- 获取表单数据
- 欢迎使用CSDN-markdown编辑器
- 稀疏表Sparse Table--uva 11235 Frequent values
- Java文件下载的几种方式
- Python 线程条件(Condition),(线程等待另一个线程的执行)
- 前端HTML5几种存储方式的总结
- JDBC基础学习
- NKOJ 3792 分糖果(差值dp+前缀和优化)