HDU 5074 Hatsune Miku (线性dp)

ADS新手必看:5分钟搞定Smith圆图阻抗匹配(附详细操作截图) 本文为射频电路设计新手提供了在ADS软件中快速使用Smith圆图进行阻抗匹配的实战指南。通过清晰的步骤和操作截图,详细演示了如何从负载阻抗点出发,通过添加电感和电容元件,在5分钟内完成向50欧姆标准阻抗的匹配,并介绍了仿真验证与性能调优的方法,帮助工程师和学生直观掌握这一核心技能。 阅读详情


Hatsune Miku

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Total Submission(s): 654    Accepted Submission(s): 471

Problem Description
Hatsune Miku is a popular virtual singer. It is very popular in both Japan and China. Basically it is a computer software that allows you to compose a song on your own using the vocal package.

Today you want to compose a song, which is just a sequence of notes. There are only m different notes provided in the package. And you want to make a song with n notes.


Also, you know that there is a system to evaluate the beautifulness of a song. For each two consecutive notes a and b, if b comes after a, then the beautifulness for these two notes is evaluated as score(a, b).

So the total beautifulness for a song consisting of notes a1, a2, . . . , an, is simply the sum of score(ai, ai+1) for 1 ≤ i ≤ n - 1.

Now, you find that at some positions, the notes have to be some specific ones, but at other positions you can decide what notes to use. You want to maximize your song’s beautifulness. What is the maximum beautifulness you can achieve?
 

Input
The first line contains an integer T (T ≤ 10), denoting the number of the test cases.

For each test case, the first line contains two integers n(1 ≤ n ≤ 100) and m(1 ≤ m ≤ 50) as mentioned above. Then m lines follow, each of them consisting of m space-separated integers, the j-th integer in the i-th line for score(i, j)( 0 ≤ score(i, j) ≤ 100). The next line contains n integers, a1, a2, . . . , an (-1 ≤ ai ≤ m, ai ≠ 0), where positive integers stand for the notes you cannot change, while negative integers are what you can replace with arbitrary notes. The notes are named from 1 to m.
 

Output
For each test case, output the answer in one line.
 

Sample Input
  
2 5 3 83 86 77 15 93 35 86 92 49 3 3 3 1 2 10 5 36 11 68 67 29 82 30 62 23 67 35 29 2 22 58 69 67 93 56 11 42 29 73 21 19 -1 -1 5 -1 4 -1 -1 -1 4 -1
 

Sample Output
  
270 625
 

Source
2014 Asia AnShan Regional Contest

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5074

题目大意:输入一个m*m的矩阵map[][]和一个长度为n的序列a1a2...an,则结果为map[a1][a2]+map[a2][a3]+...+map[an-1][an],问题是序列里可能有-1,-1可以代表1-m中的任何数,现在问怎样选择序列,可以使最后的结果值最大,输出最大值

题目分析:线性dp,dp[i][j]表示序列的第i个位置上放的是数字j,则分成4种情况
1)a[i] > 0 && a[i - 1] > 0,此时两个点位置都确定直接加即可
2)a[i] > 0 && a[i - 1] <= 0,此时前一点位置不确定,枚举前一点位置
3)a[i] <= 0 && a[i - 1] > 0,此时后一点位置不确定,枚举后一点位置
4)a[i] <= 0 && a[i - 1] <= 0,前后都不确定,分别枚举前后两点

最后答案在dp[n][i]中取大,(1 <= i <= m)表示第n个位置放1-m 中的最大值

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[105][55], map[55][55], a[105];

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n, m;
        scanf("%d %d", &n, &m);
        for(int i = 1; i <= m; i++)
            for(int j = 1; j <= m; j++)
                scanf("%d ", &map[i][j]);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        memset(dp, 0, sizeof(dp));
        for(int i = 2; i <= n; i++)
        {
            if(a[i] > 0)
            {
                if(a[i - 1] > 0)
                    dp[i][a[i]] = dp[i - 1][a[i - 1]] + map[a[i - 1]][a[i]];
                else
                    for(int j = 1; j <= m; j++)
                        dp[i][a[i]] = max(dp[i][a[i]], dp[i - 1][j] + map[j][a[i]]);
            }
            else
            {
                for(int j = 1; j <= m; j++)
                {
                    if(a[i - 1] > 0)
                        dp[i][j] = dp[i - 1][a[i - 1]] + map[a[i - 1]][j];
                    else
                        for(int k = 1; k <= m; k++)
                            dp[i][j] = max(dp[i][j], dp[i - 1][k] + map[k][j]);
                }
            }
        }
        int ans = 0;
        for(int i = 1; i <= m; i++)
            ans = max(ans, dp[n][i]);
        printf("%d\n", ans);
    }
}


单精度浮点数存储、双精度浮点数存储 阅读详情

相关推荐

手把手教你用ComfyUI搭建高效AI绘画工作流:从基础到高级技巧

本文详细介绍了如何使用ComfyUI构建高效的AI绘画工作流,从基础配置到高级技巧全面覆盖。通过模块化设计,ComfyUI显著提升显存利用率和创作灵活性,适合从新手到专业用户。文章包含部署指南、工作流搭建、性能优化及行业应用案例,帮助读者快速掌握AI绘画核心技术。

7up55的博客 720

HDU1397 POJ2909 UVA686 UVALive5674 ZOJ1657 Goldbach's Conjecture(II)【水题+打表】

Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7178    Accepted Submission(s): 2788 Problem Description Goldbach

海岛Blog 2058

别再翻手册了!用Materials Studio的Forcite模块,5步搞定复杂溶剂的溶解度参数计算

本文详细介绍了如何使用Materials Studio的Forcite模块,通过5个步骤快速计算复杂溶剂的溶解度参数。从分子建模、结构优化到分子动力学采样,再到最终的内聚能密度计算,该方法大幅提升了石油化工和高分子材料研发中的效率,避免了传统手册查阅和实验的繁琐过程。

weixin_28707739的博客 280

HDU/HDOJ 1399 Starship Hakodate-maru Asia 2001, Hakodate (Japan)

Starship Hakodate-maru Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 3Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia ...

lilisalo 1568

无网络环境部署:手动获取并安装OneNote for Windows 10完整指南

本文提供了一份详尽的OneNote for Windows 10离线安装指南。针对无网络或内网隔离环境,详细介绍了如何从官方渠道获取正确的产品ID,利用第三方工具下载纯净的.appxbundle安装包,并解决系统兼容性与依赖框架问题。最后,通过PowerShell管理员命令完成安全部署,是IT管理员和高级用户在离线环境下部署UWP应用的实用参考。

loss4bartender的博客 496

DeepSeek+Dify实战:零代码构建智能SQL生成器

本文详细介绍了如何利用DeepSeek和Dify零代码构建智能SQL生成器,帮助非技术人员通过自然语言查询数据库。文章涵盖从数据准备、知识库设计到Agent配置的全流程,并提供了优化技巧和实际应用案例,显著提升团队数据查询效率。

weixin_29311017的博客 419

hdu5074-递推-Hatsune Miku

http://acm.hdu.edu.cn/showproblem.php?pid=5074 给一串数字,若为负数。。可以变化,若为正数,不能变。 问你他们 从任意相邻两个在一起构成一个价值r[i,j] 要求 价值和最大。 规定 r(i,j)为 左边为i,右边为j 的价值。 方法;保留长度为len, 后面大小为j的情况。 递推。#include <bits/stdc++.h> using

天与云与山与水 349

maya中的几个热盒(空格、shift、w键)

maya中许多功能打包放进了不同的热盒中,让我们使用起来更加的便捷,熟练掌握后可以大大提升了建模速度。按下不同按键后鼠标不需要精确点到某个图标,往某个方向滑滑滑就打开了相应功能,非常的炫酷和迅猛。

m0_71983242的博客 1756

hdu 5074

思路: 很容易想到dp  我们只需要维护 以第i个数以 j 结尾的最大值就好了,结果就可以直接转移了 相当于每次两个for循环枚举前一个和后一个,我是分四种情况:  当前是否为-1 ,前一个是否为-1  #include using namespace std; int a[1000]; int b[200][200]; int dp[200][200]; int main() { i

theflowerofac^MQLYES的专栏 466

WPF窗口定位技巧:从基础到高级的三种实现方法

本文详细解析WPF窗口定位的三种核心方法:屏幕居中(CenterScreen)、父窗口居中(CenterOwner)和手动定位(Manual)。通过对比其适用场景、实现代码与注意事项,帮助开发者根据实际需求选择最佳方案,从而提升WPF应用程序的用户体验与专业度。

weixin_29224309的博客 272

会话管理技巧——如何优化OpenClaw的上下文理解能力(2026进阶版)

本文深入探讨了OpenClaw系统的会话管理技术,重点介绍了会话定义、生命周期管理和上下文优化策略。会话管理包含会话ID、用户信息、状态等核心要素,以及创建、维护、终止和恢复四个生命周期阶段。上下文管理通过ContextManager类实现,支持创建、更新、消息添加和变量管理等功能,并采用历史记录机制确保会话连续性。ContextOptimizer类则负责应用优化规则,通过消息和变量压缩等技术提升系统性能。这些技术共同构建了OpenClaw强大的会话管理能力,为AI助手提供了高质量的交互体验基础。

博客 491

hdu1067 N - Gap

Home Problems Status Contest [ak1] Logout WUST ACM CLUB SUMMER TRAINING (3) 277:06:36 307:00:00 Overview Problem Status Rank A B C D E F G H I J K L M N O

习惯与规则决定命运 1973

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

hdu 5074 Hatsune Miku【DP】

Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1495    Accepted Submission(s): 1015 Problem Description Hatsune Miku is

mengxiang000000 1万+

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

【HDU-1540】【Tunnel Warfare】

During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except t...

哇哈哈哈的博客 334

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

hdu5074 Hatsune Miku 2014鞍山现场赛E题 水dp

http://acm.hdu.edu.cn/showproblem.php?pid=5074 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 325    Accepted Submission(s

689

POJ 3067 Japan (树状数组 + 逆序数)

思路: 复习一发树状数组。 树状数组的核心思想:求当前插入的所有的数中,小于某个数(位置)的数的和(个数)是多少。 通过这个也可以很快的求出一个序列的逆序数。 本题问的是十字路口(crossing)的数量,通过画图我们可以得知当我们按照这个二分图的左边按序号顺序来连线的话,假设我们当前左边的序号为i,那么当处理到左边序号i+1时,我们发现,只要这个当前的y小于之前的某个y,那么即对结果贡献+1。而这

普通で歩む 411

Hdu 5074

给你一串数字代表一首乐曲,

时有限 722

hdu 5074——Hatsune Miku

题意:要用一些片段组成一首歌,歌曲的

char256 643

HDU - 1540 Tunnel Warfare (奇妙的解法)

题目描述: During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Ex

AC即性感 856

hdu1540(线段树维护连续区间模型)

/* translation: 打地道战,n个村庄用地道连成一条直线,鬼子有时破坏掉一个村庄,这时八路军要修好这个据点。现在要求询问任意一个村庄, 得出这个村庄现在与几个村庄相连,包括它本身。 solution: 线段树维护连续子区间 将村庄抽象成一个点,正常下值为1,被破坏后变成0,即可将题目抽象成一个求目标节点所在的最长连续1序列的区间的长度。 所以在线段树里面维护3个信息,前缀最长

林伏案的博客 3562

HDUOJ--------(1312)Red and Black

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6905    Accepted Submission(s): 4384 Problem Description There is a rectangul...

weixin_34122604的博客 167

hdu 5074

http://acm.hdu.edu.cn/showproblem.php?pid=5074

u012342878的专栏 576

【HDU】4000Fruit Ninja(树状数组+思维)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3642    Accepted Submission(s): 1113   Problem Description Recently, dobby is addi...

红点雷龙XL 312

Hatsune Miku+hdu+鞍山区域赛+简单dp

NEW~ 关于举办计算机学院大学生程序设计竞赛(2014'11)的报名通知 Hatsune Miku Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 100    Accepted Submission(s)

u012870383的专栏 912

HDU ACM-1087 求最大加权路径

大致算法: 从左往右,记录每个位置所有符合要求的最后一个数数值&加权和,分别放在一个数组中维护,最后在数组中取得最大值。 AC代码: #include <stdio.h> int main() { while (1) { int N = 0; scanf("%d", &N); if (N == 0) ...

dzchlj的博客 233

japan

お前には関係ない。おまえにはかんけいない。跟你没关系。

linuxtoproot的专栏 724
上一篇: HDU 5176 The Experience of Love (带权并查集 + 贪心)
下一篇: POJ 1780 Code (欧拉回路 +构造)
_TCgogogo_
博客等级 码龄12年 615粉丝 1081原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值