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 ...
随机推荐
- MAVEN项目的搭建
MAVEN能为我们做什么? 1.Jar的声明式依赖性管理 2.项目的自动构建 搭建流程 环境配置 http://maven.apache.org/download.html 下载最新版本Maven 3 ...
- plsql里面执行正常,java运行报ORA-01722: 无效数字
贴代码: <select id="getInfo" parameterClass="java.util.HashMap" resultClass=&quo ...
- Weblogic常用监控指标
http://blog.csdn.net/konglongaa/article/details/53897562
- Apache负载均衡与Tomcat集群配置学习(Windows环境)
本文主要参考自http://www.iteye.com/topic/985404?dhcc,经由实际操作配置操并记录而成. 由于最近的一个Java开发项目用到了Tomcat中间件作为web服务器,刚开 ...
- 51nod 1413:权势二进制
1413 权势二进制 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注 一个十进制整数被叫做权势二进制,当他的十进制 ...
- DirectX11 学习笔记4 - 一个完整的封装框架
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3EzNjExMDYzMDY=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
- UVA 294 - Divisors 因子个数
Mathematicians love all sorts of odd properties of numbers. For instance, they consider 945 to be an ...
- sklearn中的数据预处理----good!! 标准化 归一化 在何时使用
RESCALING attribute data to values to scale the range in [0, 1] or [−1, 1] is useful for the optimiz ...
- Java悲观锁和乐观锁
悲观的并发策略——Synchronized互斥锁 互斥锁是最常见的同步手段,在并发过程中,当多条线程对同一个共享数据竞争时,它保证共享数据同一时刻只能被一条线程使用,其他线程只有等到锁释放后才能重新进 ...