(DP 雷格码)Gray code -- hdu -- 5375
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

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)
从左边第二位起,将每位与左边一位解码后的值异或,
作为该位解码后的值(最左边一位依然不变)

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的更多相关文章
- 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——————【dp||讨论】
Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- hdu 5375 - Gray code(dp) 解题报告
Gray code Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- 递推DP HDOJ 5375 Gray code
题目传送门 /* 题意:给一个串,只能是0,1,?(0/1).计算格雷码方法:当前值与前一个值异或,若为1,可以累加a[i],问最大累加值 DP:dp[i][0/1]表示当前第i位选择0/1时的最大分 ...
- 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 ...
- HDU 5375 Gray code(2015年多校联合 动态规划)
题目连接 : 传送门 题意: 给定一个长度为的二进制串和一个长度为n的序列a[],我们能够依据这个二进制串得到它的Gray code. Gray code中假设第i项为1的话那么我们就能够得到a[i] ...
- URAL 1780 G - Gray Code 找规律
G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- LeetCode: Gray Code 解题报告
Gray CodeThe gray code is a binary numeral system where two successive values differ in only one bit ...
- hdu5375 Gray code
Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary ...
随机推荐
- three.map.control
网址:https://github.com/anvaka/three.map.control 在threejs群里发现的一个很有意思的问题之前没有接触过: 存在的问题: 我在微信小游戏中,用orbi ...
- 转 C++函数返回值,你必须注意的问题
归根结底,C++所面临的问题要求它提供各种各样的机制以保证性能,也许,这辈子也见不到C++能安全有效的自己进行内存垃圾回收..... 老程序猿都会提醒菜鸟,注意函数的返回值,因为,很可能,你的函数返回 ...
- find和find_if,value_type
find算法:返回 [first,end)中第一个值等于value元素的位置 线性复杂度:最多比较次数:元素的总个数 find函数的最后一个参数,必须是string,float,char,double ...
- 三种简单排序算法(java实现)
一.冒泡排序 算法思想:遍历待排序的数组,每次遍历比较相邻的两个元素,如果他们的排列顺序错误就交换他们的位置,经过一趟排序后,最大的元素会浮置数组的末端.重复操 作 ...
- 758B Blown Garland
B. Blown Garland time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- BZOJ1855 股票交易 单调队列优化 DP
描述 某位蒟佬要买股票, 他神奇地能够预测接下来 T 天的 每天的股票购买价格 ap, 股票出售价格 bp, 以及某日购买股票的上限 as, 某日出售股票上限 bs, 并且每次股票交 ♂ 易 ( 购 ...
- UI设计:C4D作品案例分享
中文名4D电影,外文名CINEMA 4D,研发公司为德国Maxon Computer,特点为极高的运算速度和强大的渲染插件,使用在电影<毁灭战士>.<阿凡达>中,获得贸易展中最 ...
- 【CSS小技巧】 用 CSS 实现一个宽高等比自适应容器
不知道怎么起个标题能更加清楚的说清楚我的意图,那就打个比方吧:比如我们在手机端上放一张宽度 100% 的图片,我们如果不设置图片的高度,那么这个图片会根据图片的原始尺寸等比缩放.今天我们要讲的就是实现 ...
- object SparkStreaming_StateFul {
窗口查询 ) )).reduceByKeyAndWindow(_+_,_-_,Seconds(10),Seconds(15)) 每隔15s进行查询,查询为前10s的结果.这里的值必须为采集时间 ...
- 玩具谜题(NOIP2016)
题目链接:玩具谜题 提高组日常水题. 直接模拟,有需要注意的点会在代码后讲解: #include<bits/stdc++.h> using namespace std; int main( ...