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

Gray code

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 988    Accepted Submission(s): 551

Problem Description
The reflected binary code, also known as Gray code after Frank Gray, is a binary numeral system where two successive values differ in only onebit (binary digit). The reflected binary code was originally designed to prevent spurious output from electromechanical switches. Today, Gray codes are widely used to facilitate error correction in digital communications such as digital terrestrial television and some cable TV systems.

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.

 
Input
The first line of the input contains the number of test cases T.

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)

 
Output
For each test case, output “Case #x: ans”, in which x is the case number counted from one,’ans’ is the points you can get at most
 
Sample Input
2
00?0
1 2 4 8
????
1 2 4 8
 
Sample Output
Case #1: 12
Case #2: 15
 
雷格码:

从左边第二位起,将每位与左边一位解码后的值异或,

作为该位解码后的值(最左边一位依然不变)

DPor模拟

明白格雷码转二进制怎么转就好做,DP的话dp[i][j]代表i这个位置数字是j(0or1)的时候的最大值。
如果不是问号可能某些情况是不能到达的,不能到达的情况赋一个极小值就好了。

模拟的话就是一个类似于贪心的思路,其实就是找出一串问号两边是什么情况,一串问号我们可以全转化为1,但是邻接的非问号字符不一定是什么情况,如果一边一个0一边一个1的话就贪心进行取舍就好了

 
 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; const int N = ;
const int oo = 0x3f3f3f3f; char s[N];
int dp[N][], a[N]; int main()
{
int T, iCase=; scanf("%d", &T); while(T--)
{
int len, i;
scanf("%s", s); len = strlen(s); for(i=; i<len; i++)
dp[i][] = dp[i][] = -oo;
memset(a, , sizeof(a)); for(i=; i<len; i++)
scanf("%d", &a[i]); if(s[]=='' || s[]=='?')
dp[][] = a[];
if(s[]=='' || s[]=='?')
dp[][] = ; for(i=; i<len; i++)
{
if(s[i]=='' || s[i]=='?')
dp[i][] = max(dp[i-][], dp[i-][]+a[i]);
if(s[i]=='' || s[i]=='?')
dp[i][] = max(dp[i-][], dp[i-][]+a[i]);
} printf("Case #%d: %d\n", iCase++, max(dp[len-][], dp[len-][]));
} return ;
}
 

(DP 雷格码)Gray code -- hdu -- 5375的更多相关文章

  1. HDU 5375 Gray code (简单dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Oth ...

  2. HDU 5375——Gray code——————【dp||讨论】

    Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  3. hdu 5375 - Gray code(dp) 解题报告

    Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  4. 递推DP HDOJ 5375 Gray code

    题目传送门 /* 题意:给一个串,只能是0,1,?(0/1).计算格雷码方法:当前值与前一个值异或,若为1,可以累加a[i],问最大累加值 DP:dp[i][0/1]表示当前第i位选择0/1时的最大分 ...

  5. 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 S ...

  6. HDU 5375 Gray code(2015年多校联合 动态规划)

    题目连接 : 传送门 题意: 给定一个长度为的二进制串和一个长度为n的序列a[],我们能够依据这个二进制串得到它的Gray code. Gray code中假设第i项为1的话那么我们就能够得到a[i] ...

  7. URAL 1780 G - Gray Code 找规律

    G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  8. LeetCode: Gray Code 解题报告

    Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit ...

  9. hdu5375 Gray code

    Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary ...

随机推荐

  1. 线程 day40

    操作系统线程理论 线程概念的引入背景 进程 之前我们已经了解了操作系统中进程的概念,程序并不能单独运行,只有将程序装载到内存中,系统为它分配资源才能运行,而这种执行的程序就称之为进程.程序和进程的区别 ...

  2. DevExpress XPO 开发指南 简要

    最近在看devexpress   安装程序中的代码Demos ..  C:\Users\Public\Documents\DevExpress Demos 16.1\Components\WinFor ...

  3. static ,const

    函数原型作用域:作用范围为函数形参表范围,起始于“(”,结束于“)”,这是声明 定义是属于局部作用域,所以声明的时候不写形参名字也可以 类作用域:包含类体及在类外实现的本类成员函数的函数体 静态生存期 ...

  4. Jsonpath的基本使用

    JSONPath - 是xpath在json的应用. xml最大的优点就有大量的工具可以分析,转换,和选择性的提取文档中的数据.XPath是这些最强大的工具之一.   如果可以使用xpath来解析js ...

  5. 11. pt-heartbeat

    pt-heartbeat [OPTIONS] [DSN] --update|--monitor|--check|--stop ------------------------------------- ...

  6. 教你避雷!网页设计中常见的17个UI设计错误集锦(附赠设计技巧)

    以下内容由摹客团队翻译整理,仅供学习交流,摹客iDoc是支持智能标注和切图的产品协作设计神器. 精心设计的用户界面对网站意义重大.具备所有最新功能和响应式设计有助于提高网站的搜索引擎排名,从而增加受众 ...

  7. NotificationMangerService处理显示通知

    设置——>应用——>点击“已下载”列表中的任一APP,如图:  代码位置:Settings\src\com\android\settings\applications\InstalledA ...

  8. [C#.Net]对WinForm应用程序的App.config的使用及加密

    我们在写C#应用程序时,在工程文件中放置一个app.config,程序打包时,系统会将该配置文件自动编译为与程序集同名的.exe.config 文件.作用就是应用程序安装后,只需在安装目录中找到该文件 ...

  9. Peter的烟(水题测试2017082401&洛谷1150)

    题目链接:Peter的烟 这道题基本做法很水,不解释. #include<bits/stdc++.h> using namespace std; int main(){ int n,k; ...

  10. 2018.11.24 loj#111. 后缀排序(后缀数组)

    传送门 后缀排序模板题. 终于会后缀数组了(然而只会倍增并不会DC3DC3DC3). 在这里列举几个数组的意思: sai:sa_i:sai​:当前排名第iii的后缀的起始下标. rkirk_irki​ ...