(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 ... 
随机推荐
- Linux下实时查看GPU状态
			参考链接: http://blog.csdn.net/yao_yao_2015/article/details/53404389 1. 显示当前GPU使用情况 Nvidia自带了一个nvidia-sm ... 
- 使用clear来清除localStorage保存对象的全部数据
			<!doctype html> <html> <head> <meta charset="utf-8"> <title> ... 
- iOS通过URL构建UIImage
			很多时候我们只能得到一个URL,然后需要构建一个UIImage. 通常情况下,我们一般都是通过SDWebImage来直接构建UIImageVIew的image,如何用URL直接构建UIImage呢? ... 
- Spring IOC(八)bean 的创建
			Spring IOC(八)bean 的创建 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) 参考: 每天用心记录一点点.内 ... 
- c++11 初始化列表  bind function 示例
			// 111111111111.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #incl ... 
- Clover相关知识
			-f 重建驱动缓存 darkwake=4 有深度睡眠有关的设置,不懂 kext-dev-mode=1 启用第三方驱动,比较重要. dart=0 修复因开启 VT-d 导致系统启动时SMC五国错误,系统 ... 
- linux关机命令-shutdown
			shutdown1.作用shutdown命令的作用是关闭计算机.root用户关机时,不管是否还有其他登录用户,都会关机:如果是非root用户关机,如果还有其他的登录用户,将会提示不能关机.2.格式sh ... 
- NOIP2017提高组预赛详解
			NOIP2017预赛终于结束了. 普遍反映今年的卷子难度较大,但事实上是这样吗?马上我将为您详细地分析这张试卷,这样你就能知道到底难不难. 对了答案,鄙人考得还是太差了,只有91分. 那么下面我们就一 ... 
- 浅谈System.gc()
			今天巩固给大家讲讲System.gc().Java的内存管理着实给各位编程者带来很大的方便,使我们不再需要为内存分配烦太多神.那么讲到垃圾回收机制,就不得不讲讲System.gc(). 先简单 ... 
- 求一个数的n次幂
			1.当这个数是2的多少次幂: 求(2^m)^n = 2^(m*n) = 1<<m*n; 2.快速幂(要考虑底数a,和m的正负) int quick_mod(int a,int m){ ... 
