Codeforces Round #162 (Div. 1) C Choosing Balls dp
来源:互联网 发布:数据复制 编辑:程序博客网 时间:2024/05/21 13:54
//dp[i] 表示以颜色为i结尾的最大值
//dp[i] = max(dp[i] , dp[i] + a*v[i] ,other_max + b*v[i]) ;
//为除颜色i以外的其它颜色的最大值
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 100010 ;
const __int64 inf = 0x7fffffffffffffff;
__int64 dp[maxn] ;
__int64 c[maxn] ;
__int64 v[maxn] ;
int main()
{
// freopen("input.txt","r" ,stdin) ;
int n , q;
while(~scanf("%d%d" ,&n ,&q))
{
for(int i = 1;i <= n;i++)
scanf("%I64d" ,&v[i]) ;
for(int i = 1;i <= n;i++)
scanf("%I64d" ,&c[i]) ;
while(q--)
{
for(int i = 1;i <= n;i++)
dp[i] = -inf;
__int64 a,b;
scanf("%I64d%I64d" ,&a ,&b) ;
__int64 ma = 0, ma_s = 0, ma_c = 0;
for(int i = 1;i <= n;i++)
{
__int64 temp_b;
__int64 temp_a;
if(dp[c[i]] == -inf)
temp_a = b*v[i];
else
temp_a = a*v[i] + dp[c[i]] ;
if(ma_c == c[i])
{
temp_b = b*v[i] + ma_s;
dp[c[i]] = max(max(dp[c[i]] , temp_b) ,temp_a) ;
ma = max(ma , dp[c[i]]);
}
else
{
temp_b = b*v[i] + ma;
dp[c[i]] = max(max(dp[c[i]] , temp_b),temp_a);
if(dp[c[i]] >= ma)
{
ma_s = ma;
ma_c = c[i] ;
ma = dp[c[i]] ;
}
else ma_s = max(ma_s , dp[c[i]]);
}
}
printf("%I64d\n" , ma) ;
}
}
return 0;
}
//dp[i] = max(dp[i] , dp[i] + a*v[i] ,other_max + b*v[i]) ;
//为除颜色i以外的其它颜色的最大值
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std ;
const int maxn = 100010 ;
const __int64 inf = 0x7fffffffffffffff;
__int64 dp[maxn] ;
__int64 c[maxn] ;
__int64 v[maxn] ;
int main()
{
// freopen("input.txt","r" ,stdin) ;
int n , q;
while(~scanf("%d%d" ,&n ,&q))
{
for(int i = 1;i <= n;i++)
scanf("%I64d" ,&v[i]) ;
for(int i = 1;i <= n;i++)
scanf("%I64d" ,&c[i]) ;
while(q--)
{
for(int i = 1;i <= n;i++)
dp[i] = -inf;
__int64 a,b;
scanf("%I64d%I64d" ,&a ,&b) ;
__int64 ma = 0, ma_s = 0, ma_c = 0;
for(int i = 1;i <= n;i++)
{
__int64 temp_b;
__int64 temp_a;
if(dp[c[i]] == -inf)
temp_a = b*v[i];
else
temp_a = a*v[i] + dp[c[i]] ;
if(ma_c == c[i])
{
temp_b = b*v[i] + ma_s;
dp[c[i]] = max(max(dp[c[i]] , temp_b) ,temp_a) ;
ma = max(ma , dp[c[i]]);
}
else
{
temp_b = b*v[i] + ma;
dp[c[i]] = max(max(dp[c[i]] , temp_b),temp_a);
if(dp[c[i]] >= ma)
{
ma_s = ma;
ma_c = c[i] ;
ma = dp[c[i]] ;
}
else ma_s = max(ma_s , dp[c[i]]);
}
}
printf("%I64d\n" , ma) ;
}
}
return 0;
}
0 0
- Codeforces Round #162 (Div. 1) C Choosing Balls dp
- codeforces 264C Choosing Balls (dp)
- CodeForces 264C Choosing Balls dp(水
- Codeforces 264 C. Choosing Balls
- 264C - Choosing Balls DP
- 【dp】Codeforces Round #110 (Div. 1) C
- C. Kyoya and Colored Balls(Codeforces Round #309 (Div. 2))
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls
- Codeforces Round #162 (Div. 1) B dp
- Codeforces Round #135 (Div. 2) - D. Choosing Capital for Treeland(dfs / 树形DP)
- Codeforces Round #309 (Div. 1) A Kyoya and Colored Balls
- 【DP】-Codeforces Round #110 (Div. 1)-C. Cipher
- Codeforces Round #272 (Div. 1)C(字符串DP)
- Codeforces Round #248 (Div. 1)C(AC自动机+DP)
- Codeforces Round #148 (Div. 1)C 树形dp
- Codeforces Beta Round #96 (Div. 1) C. Logo Turtle (DP)
- Codeforces Round #363 (Div. 1) C. LRU(状态压缩dp)
- tomcat多域名配置
- Android开发的一些需要注意的细节
- Ubuntu13.04下Eclipse中文乱码解决
- android开发框架集合简介
- Javascript 动态增减元素
- Codeforces Round #162 (Div. 1) C Choosing Balls dp
- container_of
- data mining - 实用机器学习工具与技术 - 读书笔记( 一 )
- Spring+监听器+Quartz集群(1)——基本配置
- Jackson的使用
- 求二叉树宽度
- 瘦针灸减肥效果 v信616628874
- 服务器配置Apache+多个tomcat
- setInterval的停止方法