HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水
简单dp
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
typedef unsigned long long ull;
const int N = 105;
int n, m, a[N];
int s[N][N], dp[2][N];
void pt(int x ){
for(int i = 1; i <= m; i++)printf("%d ", dp[x][i]); puts("");
}
int solve(){
int cur = 0;
if(a[1] < 0)
memset(dp[cur], 0, sizeof dp[cur]);
else
{
memset(dp[cur], -1, sizeof dp[cur]);
dp[cur][a[1]] = 0;
}
for(int i = 2; i <= n; i++)
{
cur ^= 1;
memset(dp[cur], -1, sizeof dp[cur]);
if(a[i]>0)
{
for(int j = 1; j <= m; j++)
if(dp[cur^1][j] != -1)
dp[cur][a[i]] = max(dp[cur][a[i]], dp[cur^1][j] + s[j][a[i]]);
}
else
{
for(int j = 1; j <= m; j++)
if(dp[cur^1][j]!=-1)
for(int k = 1; k <= m; k++)
dp[cur][k] = max(dp[cur][k], dp[cur^1][j]+s[j][k]);
}
// cout<<i<<":"; pt(cur);
}
int ans = 0;
for(int i = 1; i <= m; i++)
ans = max(ans, dp[cur][i]);
return ans;
}
void input(){
cin>>n >> m;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= m; j++)
scanf("%d", &s[i][j]);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
}
int main(){
int T; cin>>T;
while(T--){
input();
cout<<solve()<<endl;
}
return 0;
}
/*
9
3 3
1 1 5
5 1 100
1 5 1
-1 -1 -1 */
HDU 5074 Hatsune Miku 2014 Asia AnShan Regional Contest dp(水的更多相关文章
- dp --- 2014 Asia AnShan Regional Contest --- HDU 5074 Hatsune Miku
Hatsune Miku Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5074 Mean: 有m种音符(note),现在要从 ...
- HDU 5074 Hatsune Miku(2014鞍山赛区现场赛E题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5074 解题报告:给出一个长度为n的序列,例如a1,a2,a3,a4......an,然后这个序列的美丽 ...
- 2014 Asia AnShan Regional Contest --- HDU 5073 Galaxy
Galaxy Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5073 Mean: 在一条数轴上,有n颗卫星,现在你可以改变k颗 ...
- 2014 Asia AnShan Regional Contest --- HDU 5078 Osu!
Osu! Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5078 Mean: 略. analyse: 签到题,直接扫一遍就得答 ...
- HDU 5073 Galaxy 2014 Asia AnShan Regional Contest 规律题
推公式 #include <cstdio> #include <cmath> #include <iomanip> #include <iostream> ...
- hdu5071 2014 Asia AnShan Regional Contest B Chat
模拟题: add的时候出现过的则不再添加 close的时候会影响到top rotate(Prior.Choose)的时候会影响到top /*============================== ...
- hdu5072 2014 Asia AnShan Regional Contest C Coprime
最后一次参加亚洲区…… 题意:给出n(3 ≤ n ≤ 105)个数字,每个数ai满足1 ≤ ai ≤ 105,求有多少对(a,b,c)满足[(a, b) = (b, c) = (a, c) = 1] ...
- hdu oj 3127 WHUgirls(2009 Asia Wuhan Regional Contest Online)
WHUgirls Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
- 2014 ACM-ICPC Asia Anshan Regional Contest(Online Version)
题目I - Osu! - HDU 5078 题目分析:最水的一道题吧,求两点间的距离和时间差值的最大比值 #include<stdio.h> #include<math.h> ...
随机推荐
- iOS-UI控件之UIImageView
contentMode属性 带有scale单词的:图片有可能会拉伸 UIViewContentModeScaleToFill 将图片拉伸至填充整个imageView 图片显示的尺寸跟imageView ...
- SQL 索引自动维护计划脚本
脚本功能: 1,查询数据库中,碎片率在5%以上(官方推荐),有一定数据里的表的索引. 2.如果碎片率在5%<碎片率<=30% 执行重新组织索引.如果在30%以上,执行重建索引 建议在执行 ...
- C#运用存储过程新增一条记录并返回自动生成的ID
@Hcy黄灿奕:http://blog.sina.com.cn/iihcy 前言: 1.存储过的好处: 存储过程相对于其他的数据库访问方法有以下的优点: (1)重复使用.存储过程可以重复使用,从而可以 ...
- OpenFlow_tutorial_2_Install_Required_Software
一.Required Software 我操作系统用的 ubuntu 18.04.vm image的OS是ubuntu14.04,这两个系统的GUI应该已经不兼容了,如果使用ubuntu18.04的主 ...
- [CodeForces]1059D Nature Reserve
大意:给你一个平面上N(N<=100000)个点,问相切于x轴的圆,将所有的点都覆盖的最小半径是多少. 计算几何???Div2的D题就考计算几何???某人昨天上课才和我们说这种计算几何题看见就溜 ...
- CAD参数绘制直径标注(网页版)
主要用到函数说明: _DMxDrawX::DrawDimDiametric 绘制一个直径标注.详细说明如下: 参数 说明 DOUBLE dChordPointX 在被标注的曲线上的第一个点X值 DOU ...
- 复制Windows的等宽字体到Linux
1.从Windows的Fonts目录下复制字体 2.在Linux的/usr/share/fonts目录下创建子目录例如:sudo mkdir /usr/share/fonts/win 3.复制字体到该 ...
- UTF-8,UTF-16
UTF是 Unicode Translation Format,即把Unicode转做某种格式的意思. 在Unicode基本多文种平面定义的字符(无论是拉丁字母.汉字或其他文字或符号),一律使用2字节 ...
- RNN,LSTM,GRU基本原理的个人理解
记录一下对RNN,LSTM,GRU基本原理(正向过程以及简单的反向过程)的个人理解 RNN Recurrent Neural Networks,循环神经网络 (注意区别于recursive neura ...
- CSU 2018年12月月赛 B 2214: Sequence Magic
Description 有一个1到N的自然数序列1,2,3,...,N-1,N. 我们对它进行M次操作,每次操作将其中连续的一段区间 [Ai,Bi][Ai,Bi] (即第Ai个元素到第Bi个元素之间的 ...