264C - Choosing Balls DP
来源:互联网 发布:oracle默认端口 编辑:程序博客网 时间:2024/05/29 10:56
总结:if elese if 还是掌握不够
#include <iostream>#include <cstdio>#define LL long long#define eps -1e17const int LMT=100003;//连接因子的判断啊using namespace std;LL v[LMT];int c[LMT];LL dp[LMT];int main(){ int n,fir,sec,q; LL a,b,tem,geta,getb,ans=0; scanf("%d%d",&n,&q); for(int i=1;i<=n;i++)scanf("%I64d",&v[i]); for(int i=1;i<=n;i++)scanf("%d",&c[i]); while(q--) { scanf("%I64d%I64d",&a,&b); ans=0; for(int i=0;i<=n;i++) dp[i]=eps; dp[0]=0; fir=0;sec=-1; for(int i=1;i<=n;i++) { geta=getb=eps;tem=eps; if(dp[c[i]]!=eps)tem=v[i]*a+dp[c[i]]; if(fir==c[i])geta=v[i]*a+dp[fir]; else geta=v[i]*b+dp[fir]; if(fir==c[i]&&sec!=-1) { if(sec==c[i])getb=v[i]*a+dp[sec]; else getb=v[i]*b+dp[sec]; } tem=max(max(geta,getb),tem); dp[c[i]]=max(dp[c[i]],tem); if(tem>dp[fir]&&c[i]!=fir)//这里仔细啊,条件一定要精确 { sec=fir; fir=c[i]; } else if(fir!=c[i]&&(sec==-1||tem>dp[sec]))sec=c[i]; ans=max(ans,tem); } cout<<ans<<endl; } return 0;}
- 264C - Choosing Balls DP
- codeforces 264C Choosing Balls (dp)
- CodeForces 264C Choosing Balls dp(水
- Codeforces 264 C. Choosing Balls
- 【Coder Force】264C - Choosing Balls (DP高难度思维转换)
- Codeforces Round #162 (Div. 1) C Choosing Balls dp
- CODEFORCES, 265E Choosing Balls
- Codeforces 67C. Sequence of Balls DP!
- codeforce 67C - Sequence of Balls(dp)
- codeforces 67C Sequence of Balls (dp)
- Codeforces 67C Sequence of Balls 编辑距离 dp
- Codeforces 554C Kyoya and Colored Balls 【dp + 组合数学】
- [Codeforces 67C] Sequence of Balls (字符串DP)
- hdoj5125magic balls【dp】
- zoj 3690 Choosing number(矩阵乘法+dp)
- zoj3690--Choosing number(dp,矩阵快速幂)
- Choosing Capital for Treeland (树型DP)
- CF_D. Choosing Capital for Treeland_树形DP
- 导航菜单
- 263D - Cycle in Graph 图论 YY
- 关于计算机世界的猜想
- 156C - Cipher DP yy
- 229D - Towers DP
- 264C - Choosing Balls DP
- codeforces 8C - Looking for Order 状态DP
- codeforces 117C - Cycle 图论 DFS
- 并行计算工具的选择
- 创建、选择和删除画笔
- 托管代码
- hdu 2500
- 万恶的迅雷导致的 ADB server didn't ACK
- 享元模式(FlyWeight)