【BestCoder Round #59 (div.1) B】【疯狂的火神】
来源:互联网 发布:库克和乔布斯 知乎 编辑:程序博客网 时间:2024/04/30 21:05
题目大意
t分钟有n个人可以打,如果在第x分钟单挑这个人(x指单挑完这个人的时间),就会得到a-b*x的经验值。求最大经验值。
解题思路
比较相邻两个人单挑的顺序怎样更优,发现c[i]*b[i+1]>*c[i+1]*b[i]时前后调换更优, 接着就可以dp,f[i][j]=g[j-c[i]]+a[i]-j*b[i],f[i][j]为打到第i个人用了j分钟的最大经验值,g[i]为至多打到第i-1个人用了至多j分钟的最大经验值。
code
//#include<set>#include<cmath>#include<cstdio>#include<cstring>#include<algorithm>#define LF double#define LL long long#define fo(i,j,k) for(int i=j;i<=k;i++)#define fd(i,j,k) for(int i=j;i>=k;i--)using namespace std;int const maxn=1000,maxt=3000;int n,t,a[maxn+10],b[maxn+10],c[maxn+10],f[maxn+10][maxt+10],g[maxt+10];int main(){ freopen("d.in","r",stdin); freopen("d.out","w",stdout); int tt;scanf("%d",&tt); fo(cas,1,tt){ scanf("%d%d",&n,&t); fo(i,1,n)scanf("%d%d%d",&a[i],&b[i],&c[i]); fo(j,1,n-1) fo(i,1,n-j) if(1ll*c[i]*b[i+1]>1ll*c[i+1]*b[i]){ swap(a[i],a[i+1]); swap(b[i],b[i+1]); swap(c[i],c[i+1]); } memset(f,0,sizeof(f)); memset(g,0,sizeof(g)); fo(i,1,n){ fo(j,c[i],t) f[i][j]=g[j-c[i]]+a[i]-1ll*j*b[i]; fo(j,1,t)g[j]=max(g[j-1],max(g[j],f[i][j])); } printf("%d\n",g[t]); } return 0;}
0 0
- 【BestCoder Round #59 (div.1) B】【疯狂的火神】
- 【BestCoder Round #59 (div.1) B】疯狂的火神
- 【BestCoder Round #59 (div.1) B】【JZOJ4693】疯狂的火神
- 【BestCoder Round #59 div.1 B】【JZOJ 4693】 疯狂的火神
- (BestCoder Round #59 (div.1) B)简单DP
- BestCoder Round #63 (div.1) B.matrix
- BestCoder Round #64 (div.1) B.Array
- BestCoder Round #81 (div.1) B String
- BestCoder Round #59 (div.1)
- 疯狂的火神题解
- 【JZOJ4693】疯狂的火神
- BestCoder Round #59 (div.2)B.Reorder the Books
- BestCoder Round #68 (div.1) B 矩阵乘法优化DP
- BestCoder Round #81 (div.1) A B hdu5571 hdu 5572
- BestCoder Round #78 (div.2) A B
- BestCoder Round #82 (div.2) A B
- 【JZOJ 4693】疯狂的火神
- BestCoder Round #59 (div.2)
- Tomcat异常:UnsupportedClassVersionError unsupported major.minor version 51.0 unable to load class [dup
- winpc下Mac10.11+Vmware12
- Oracle脚本工具1.0
- Python 安装 第三方库的安装技巧
- 全部清除告警后导致主界面告警数和告警界面告警数不一致
- 【BestCoder Round #59 (div.1) B】【疯狂的火神】
- 线程几种方法
- 由 mysql 存储过程无法调用引起的一串问题
- 个人记录-LeetCode 1.Two Sum
- Linux 初体验
- Could not obtain transaction-synchronized Session for current thread
- Android PLT/GOT 符号重定向过程
- RequireJS和AMD规范
- Annotation学习笔记