2015 Multi-University Training Contest 7 hdu 5375 Gray code
Gray code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 129 Accepted Submission(s): 68

Now , you are given a binary number of length n including ‘0’ , ’1’ and ‘?’(? means that you can use either 0 or 1 to fill this position) and n integers(a1,a2,….,an) . A certain binary number corresponds to a gray code only. If the ith bit of this gray code is 1,you can get the point ai.
Can you tell me how many points you can get at most?
For instance, the binary number “00?0” may be “0000” or “0010”,and the corresponding gray code are “0000” or “0011”.You can choose “0000” getting nothing or “0011” getting the point a3 and a4.
Each test case begins with string with ‘0’,’1’ and ‘?’.
The next line contains n (1<=n<=200000) integers (n is the length of the string).
a1 a2 a3 … an (1<=ai<=1000)
https://en.wikipedia.org/wiki/Gray_code
http://baike.baidu.com/view/358724.htm
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int dp[maxn][],w[maxn],len;
char str[maxn];
int main() {
int kase,cs = ;
scanf("%d",&kase);
while(kase--) {
scanf("%s",str);
len = strlen(str);
for(int i = ; i < len; ++i)
scanf("%d",w + i);
memset(dp,-,sizeof dp);
if(str[] == '' || str[] == '?') dp[][] = ;
if(str[] == '' || str[] == '?') dp[][] = w[];
for(int i = ; i < len; ++i){
if(str[i] == '' || str[i] == '?'){
if(dp[i-][] != -) dp[i][] = max(dp[i][],dp[i-][]);
if(dp[i-][] != -) dp[i][] = max(dp[i][],dp[i-][] + w[i]);
}
if(str[i] == '' || str[i] == '?'){
if(dp[i-][] != -) dp[i][] = max(dp[i][],dp[i-][]);
if(dp[i-][] != -) dp[i][] = max(dp[i][],dp[i-][] + w[i]);
}
}
printf("Case #%d: %d\n",cs++,max(dp[len-][],dp[len-][]));
}
return ;
}
2015 Multi-University Training Contest 7 hdu 5375 Gray code的更多相关文章
- HDU 5375 Gray code (简单dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 5375 Gray code(2015年多校联合 动态规划)
题目连接 : 传送门 题意: 给定一个长度为的二进制串和一个长度为n的序列a[],我们能够依据这个二进制串得到它的Gray code. Gray code中假设第i项为1的话那么我们就能够得到a[i] ...
- HDU 5375 Gray code 格雷码(水题)
题意:给一个二进制数(包含3种符号:'0' '1' '?' ,问号可随意 ),要求将其转成格雷码,给一个序列a,若转成的格雷码第i位为1,则得分+a[i].求填充问号使得得分最多. 思路:如果了 ...
- HDU 5375 Gray code
题意:给出一个二进制数,其中有些位的数字不确定,对于所有对应的格雷码,与一个序列a对应,第i位数字为1时得分a[i],求最大的得分. 解法:一个二进制数x对应的格雷码为x ^ (x >> ...
- HDU 5375——Gray code——————【dp||讨论】
Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 5375 Gray code 【 dp 】
dp[i][j]表示第i位取j的时候取得的最大的分数 然后分s[i]是不是问号,s[i-1]是不是问号这大的四种情况讨论 #include<cstdio> #include<cstr ...
- HDU 5375 Gray Code 动归
题意:给你一串不确定的二进制码,其对应的格雷码的每一位有对应的权值,问转换成的格雷码的能取到的最大权值是多少. 思路:没有思路,乱搞也AC #pragma comment(linker, " ...
- HDU 5375 Gray code(DP)
题意:给一串字符串,里面可能出现0,1,?,当中问号可能为0或1,将这个二进制转换为格雷码后,格雷码的每位有一个权值,当格雷码位取1时.加上该位权值,求最大权值和为多少. 分析:比赛的时候愚了.竟然以 ...
- hdu 5375 - Gray code(dp) 解题报告
Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
随机推荐
- Hadoop集群(第11期)_常用MySQL数据库命令
1.系统管理 1.1 连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 举例: 例1:连接到本机上的MySQL. 首先在打开DOS窗口,然后进入目录 mysqlbin,再键入 ...
- opencv3.2+opencv_contrib+cmake
转自原文 opencv3.2+opencv_contrib+cmake 心得体会 初学OpenCV发现opencv3.2(下载链接在附录)是没有xfeatures2d等模块的.第三方库opencv_c ...
- Apache + Tomcat 负载均衡 session复制
转自:http://blog.csdn.net/cssmhyl/article/details/8455400 http://snowolf.iteye.com/blog/743611 Apache ...
- Python+Django+SAE系列教程16-----cookie&session
本章我们来解说cookie和session ,这两个东西相信大家一定不陌生,概念就不多讲了,我们直接来看其使用方法,首先是cookie,我们在view中加入三个视图,一个是显示cookie的,一个是设 ...
- redis持久化,rdb,aof
RDB(Redis DataBase) AOF(Append Only File) 周阳语录:能撑过面试经理头一分钟最重要.头一分钟,决定人家还是否想跟你继续聊下去. RDB RDB就是在指定的时间内 ...
- 使用CNN做电影评论的负面检测——本质上感觉和ngram或者LSTM同,因为CNN里图像检测卷积一般是3x3,而文本分类的话是直接是一维的3、4、5
代码如下: from __future__ import division, print_function, absolute_import import tensorflow as tf impor ...
- oracle性能检测sql语句
1. 监控事例的等待 select event,sum(decode(wait_Time,0,0,1)) "Prev",sum(decode(wait_Time,0,1,0)) & ...
- Regexp-Utils:基本
ylbtech-Regexp-Utils:基本 1.返回顶部 1. /** * 管理 */ var utils = { hostUrl: "http://localhost:8023&quo ...
- jquery中命名冲突问题
例如用jq代替$符号 var jq = $.noConflict()
- 浅谈for循环
for循环 <script> /* ** (1) 是执行代码块之前 ** (2) 运行代码块的条件 ** (3) 需要执行的代码块 ** (4) 代码块执行后执行 ** 执行顺序是(1)( ...