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 ...
随机推荐
- spring boot不同环境读取不同配置
具体做法: 不同环境的配置设置一个配置文件,例如:dev环境下的配置配置在application-dev.properties中:prod环境下的配置配置在application-prod.prope ...
- 有关文档碎片(document fragment)的使用方法
通常情况下改动.删除或者添加DOM元素. 更新DOM会导致浏览器又一次绘制屏幕,也会导 致reflow,这样会带来巨大的开销.我们通常解决这的办法尽量降低更新DOM.这也就意 味着将DOM的改变分批处 ...
- python 并发编程入门
多进程 在Unix/Linux下,为我们提供了类似c中<unistd.h>头文件里的的fork()函数的接口,这个函数位于os模块中,相同与c中类似,对于父进程fork()调用返回子进程I ...
- 怎样在同一台电脑使用不同的账号提交到同一个github仓库
近期这段时间使用github.有时在公司办公,想要用git提交代码到自己的github仓库,提交是显示的作者是自己在公司的账户.而不是自己的github账户.这就相当于提交到github的代码不是自己 ...
- Flex AsDoc 完整版
Flex 生成AsDoc用的是SDK自带的asdoc.exe工具 生成AsDoc文档的方式有两种:ant或者FlashBuilder 外部配置工具 方法一:外部配置工具 新增一个外部配置工具.过程例如 ...
- HDU 2054 A==B? 大数
Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...
- docker迁移步骤
1. 创建快照:docker commit -p 30b8f18f20b4 container-backup (可以通过docker images 查看docker镜像) 2. 镜像保存在本地机器中: ...
- linux服务器卸载本机默认安装的jdk
1. 查看系统安装的版本情况: rpm -qa | grep jdk rpm -qa | grep gcj 2. 查看并删除 [root@iZ2zeedm3x12d8xb4g15a ...
- ROS中安装任意版本的OPENCV
转自:http://tieba.baidu.com/p/5023000237 安装 Opencv 3.2 on Ubuntu 16.04 并创建node测试 step 1: 安装一些package s ...
- BZOJ 1500 splay终结版...
GSS系列有一丝丝像- 只不过那个是线段树 这个是splay 翻转 插入 删除啥的就是普通的splay 合在一起了而已 //By SiriusRen #include <cstdio> # ...