ZOJ 1642
题意:有两个字符串,每个串由n个字符组成,每个字符有一个价值,Roy每次指定串2中的一个字符,他的得分增加的值为这个字符的价值,然后把两个串中这个字符前面的那部分(包括这个字符)删掉,重复进行这样的操作,求Roy最多能得多少分。
dp[i][k] 存的前str1的前i个和str2的前k个能取得最大值,接下来就不用说啥了,dp
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const int maxa = ;
int dp[maxa][maxa];
int value_char[];
char str1[maxa], str2[maxa];
int main(){
int n;
while(scanf("%d", &n)!=EOF){
for(int i = ; i < n; i++){
char c;
int d;
scanf("\n%c %d", &c, &d);
value_char[c] = d;
}
memset(dp, , sizeof(dp));
scanf("%s%s", str1, str2);
int maxu = ;
for(int i = ; str1[i]; i++){
int maxn = ;
for(int k = ; str2[k]; k++){
if(str2[k] == str1[i]){
dp[i][k] = max(maxn + value_char[str1[i]], dp[i][k]);
//printf("%d %d\n", i, k);
//dp[i+1][k] = dp[i][k];
maxu = max(maxu, dp[i][k]);
}
maxn = max(maxn, dp[i][k]);
}
for(int k = ; str2[k]; k++){
dp[i+][k] = dp[i][k];
} }
printf("%d\n", maxu);
}
}
ZOJ 1642的更多相关文章
- ZOJ 1642 Match for Bonus (DP)
题目链接 题意 : 给你两个字符串,两个字符串都有共同的字母,给你每个字母的值,规则是,找出两个字符串中的共同的一个字母,然后这个字母的值就可以加到自己的分数上,但是这步操作之后,这两个字母及其之前的 ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
随机推荐
- python之scrapy入门教程
看这篇文章的人,我假设你们都已经学会了python(派森),然后下面的知识都是python的扩展(框架). 在这篇入门教程中,我们假定你已经安装了Scrapy.如果你还没有安装,那么请参考安装指南. ...
- MMDrawerController 使用遇到的问题及定制
MMDrawerController 1,集成UIViewController * leftDrawer = [[UIViewController alloc] init]; UIViewContro ...
- Go Cookie 练习
package main import ( "io" "log" "net/http" ) func main() { http.Handl ...
- 怎样卸载goldengate
1. Log on to the database server (as oracle) where the GoldenGate software isinstalled.2. Change dir ...
- Acdream Mengzhu
http://acdream.info/problem?pid=1006 #include <cstdio> #include <cmath> #include <cst ...
- PowerShell控制台输出符号+函数参数类型指定+文本内容读取
There are several ways: Write-Host: Write directly to the console, not included in function/cmdlet o ...
- Android中程序包的相关操作
//获取系统中已经安装的应用程序 List<PackageInfo> packageinfos=this.getPackageManager().getInstalledPackages( ...
- POJ_1321——棋盘问题,回溯+剪枝
Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子 ...
- Contest - 第10届“新秀杯”ACM程序设计大赛现场热身赛 赛后信息(题解)
Problem Id Title Problem A A+B Problem B 统计字数 Problem C 生日计算 Problem D 冬瓜的寒假之旅 Problem A(略 ...
- 创建git repo
http://git-scm.com/book/en/Git-Basics-Getting-a-Git-Repository Getting a Git Repository You can get ...