[hdu5375 Gray code]DP】的更多相关文章

题意:给一个二进制码,其中有一些位上为'?',对每个问号确定是'0'还是'1',最后以它对应的格雷码来取数,第i位为1则取第i个数,求取得的数的和的最大值. 思路:二进制码B转换成格雷码G的方法是,Gi=Bi^Bi+1,Gn=Bn.所以第i位如果为'?',那么选'1'还是'0'只会影响邻位,于是用dp即可解决. #include <map> #include <set> #include <cmath> #include <ctime> #include &…
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 spuriou…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5375 题目大意:给你一个二进制串,带'?'的位置能够由你来决定填'1'还是'0',补充完整之后转换成格雷码表示,每个位置都有一个权值a[i],仅仅有格雷码为'1'的位能够加上权值,问你终于权值之和最大为多少. 格雷码表示能够百度一下,在这里能够通俗一点讲:对于这么一个串,假设i位置是1,那么他后面的数就会变化(0变1.1变0),注意仅仅是看初始串. 比如:初始串为110,那么改变以后则为101,而…
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int N=200000+5; const int inf=1<<24; int dp[N][2],a[N]; char s[2*N]; int main() { int n,m,i,_; scanf("%d",&_); for(int k=1;k<=_;k+…
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 kn…
Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 569    Accepted Submission(s): 337 Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary…
题目传送门 /* 题意:给一个串,只能是0,1,?(0/1).计算格雷码方法:当前值与前一个值异或,若为1,可以累加a[i],问最大累加值 DP:dp[i][0/1]表示当前第i位选择0/1时的最大分数,那么分类讨论,情况太多,看代码,注意不可能的状态不要转移 */ /************************************************ * Author :Running_Time * Created Time :2015-8-11 15:49:03 * File N…
题目链接: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): 626    Accepted Submission(s): 369 Problem Description The reflected binary cod…
Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 684    Accepted Submission(s): 402 Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary…
G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87643#problem/G Description Denis, Vanya and Fedya gathered at their first team training. Fedya told them that he knew the algorithm for c…