scut training 2 简单dp zoj3956
来源:互联网 发布:淘宝店铺无线端网址 编辑:程序博客网 时间:2024/06/05 04:43
这道题居然是dp
虽然最后听到别人说是dp,,但是自己还是不会,,,而且最后跟着敲得时候居然要longlong。
这道题属于01背包,, dp[i]表示c为i时最多的h,
然后根据公式:
因为当c固定时,这个式子只需要看前面 h*h-h*c=h*(h-c)
h大于c时,肯定h越大越好
h小于c时,表达式的值必定小于零,肯定是不考虑的
这个地方的通过使 c固定的方式来处理这个公式方式应该是这种题的套路吧。。做题太少了。。。不知道。。
#include<bits/stdc++.h>#define ll long longusing namespace std;const int INF=10000000;const int maxn=50050;ll h[maxn],c[maxn];ll dp[maxn];ll cal(ll c,ll h){ return h*h-h*c-c*c;}int main(){ int t; scanf("%d",&t); while(t--){ int n; memset(c,0,sizeof(c)); memset(h,0,sizeof(h)); scanf("%d",&n); int tot=0; for(int i=1;i<=n;++i) scanf("%d%d",&h[i],&c[i]),tot+=c[i]; memset(dp,0,sizeof(dp)); for(int i=1;i<=n;++i){ for(int j=tot;j>=c[i];--j){ dp[j]=max(dp[j],dp[j-c[i]]+h[i]); } } ll ans=0; for(int i=1;i<=tot;++i){ ans=max(ans,cal(i,dp[i])); } cout<<ans<<'\n'; }}
0 0
- scut training 2 简单dp zoj3956
- zoj3956(dp)
- 2016 SCUT 专题训练 简单dp
- ZOJ3956
- SCUT Training 20170913 Problem A
- SCUT Training 20170913 Problem B
- SCUT Training 20170913 Problem C
- SCUT Training 20170913 Problem D
- SCUT Training 20170913 Problem E
- SCUT Training 20170913 Problem F
- SCUT Training 20170913 Problem G
- SCUT Training 20170913 Problem H
- SCUT Training 20170913 Problem I
- SCUT Training 20170913 Problem J
- SCUT Training 20170913 Problem K
- SCUT Training 20170913 Problem L
- SCUT Training 20170913 Problem M
- SCUT Training 20170913 Problem N
- Spark Streaming 2:概述
- cas报错(No subject、'principal' cannot be null、PKIX path validation failed等错误)
- 心的路上
- 第八周作业报告
- HDU 4507 吉哥系列故事——恨7不成妻 数位DP
- scut training 2 简单dp zoj3956
- 17
- SeqQueue
- 在Eclipse中使用Maven 2.x指南
- mysql 启动失败解决
- 编译并使用boost库(win7+boost1.63+vs2015+32位or 64位)
- 分类游戏
- 【软件测试】软件缺陷定义
- 哈希表之unordered_map