hdoj 5375 Gray Code】的更多相关文章

题目传送门 /* 题意:给一个串,只能是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 编码规则:tmp = XOR(gr[i],gr[i-1]); 算是找规律的题目吧,考虑?前后字符和?数目的奇偶性就可以了,一个小trick就是当碰到需要减的时候是减问号区间内最小的那个, 然后就是调试的问题: 字符串从数组第二位开始存放,scanf("%s",s+1); 当用到min和max的时候记得每次使用前要清空. #include<stdio.h> ; int XO…
题目链接: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): 569    Accepted Submission(s): 337 Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary…
Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 129    Accepted Submission(s): 68 Problem Description The reflected binary code, also known as Gray code after Frank Gray, is a binary n…
题目连接 : 传送门 题意: 给定一个长度为的二进制串和一个长度为n的序列a[],我们能够依据这个二进制串得到它的Gray code. Gray code中假设第i项为1的话那么我们就能够得到a[i]的值,在原来的二进制串中有一些位置为? 表示能够为0, 也能够为1求最后所能得到的最大的值. 已知二进制码怎样得到Gray code请看:传送门 分析: 我们能够通过动态规划来解决问题,状态转移也很好找 ,dp[i][j]表示到第i个位置.第i个位置 取j所能得到的最大值.非常明显这个题的j仅仅能有…
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…
题意:给一个二进制数(包含3种符号:'0'  '1'  '?'  ,问号可随意 ),要求将其转成格雷码,给一个序列a,若转成的格雷码第i位为1,则得分+a[i].求填充问号使得得分最多. 思路:如果了解格雷码的转换,相信能很快看出一些端倪.偷别人的图: 分析一下:所给的二进制数要转成格雷码,只与所给二进制有关.即不需要利用已经某些转换好的格雷码字. 接下来分析5个位的串 : (1)00?00 仅有1个问号,只会与后面那些连续且非问号的串转成格雷码有关 (2)00??0 有连续的1个问号,这才需要…
题意:给出一个二进制数,其中有些位的数字不确定,对于所有对应的格雷码,与一个序列a对应,第i位数字为1时得分a[i],求最大的得分. 解法:一个二进制数x对应的格雷码为x ^ (x >> 1),题解说是个dp……但其实就四种情况……判一下就好了 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string> #include<string.h>…
dp[i][j]表示第i位取j的时候取得的最大的分数 然后分s[i]是不是问号,s[i-1]是不是问号这大的四种情况讨论 #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; ; ]; int a[maxn]; char s[maxn]; int n; int main(){ int T; scanf("%d&qu…
题意:给你一串不确定的二进制码,其对应的格雷码的每一位有对应的权值,问转换成的格雷码的能取到的最大权值是多少. 思路:没有思路,乱搞也AC #pragma comment(linker, "/STACK:1000000000") #include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #incl…
题意:给一串字符串,里面可能出现0,1,?,当中问号可能为0或1,将这个二进制转换为格雷码后,格雷码的每位有一个权值,当格雷码位取1时.加上该位权值,求最大权值和为多少. 分析:比赛的时候愚了.竟然以为格雷码是由3个二进制字符转换的,于是妥妥wa了,事实上格雷码的求法是通过异或求的的,即Gi=Bi⊕Bi-1(G为格雷码,B为二进制数),那么仅仅要水水的DP一下就好了.详细DP是通过保存 DP[i][j],当中i为当前位.j表示当前为为0还是1,递推式为: 一.s[i]为0时 1.s[i-1]为0…
#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…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Fo…
Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin…
Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Fo…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, find the sequence of gray code. A gray code sequence must begin with 0 and…
Decode Ways A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to decode it. For example, G…
Description: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must beg…
题目链接 The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with…
题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray co…
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. Fo…
题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0…
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…
Question The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin w…
题目:格雷码. 格雷码是从0开始且之后两个相邻码之间只有一个符号不相同,例如000,100,101,111三个相邻之间只有一个二进制不同. 现在给定一个数字n,然后给出格雷码所对应的数字.例如: For example, given n = 2, return [0,1,3,2]. Its gray code sequence is: 00 - 0 01 - 1 11 - 3 10 - 2 左边一列是格雷码,右边一列是对应的需要输出的十进制. 我们来观察一下格雷码的规律.如果是1那么是 0 1…
题目: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0…
知道啥是 gray code 就是收获了. 下面介绍了 gray code 发明的 motivation, 了解动机后就知道啥是 gray code 了. https://zh.wikipedia.org/wiki/格雷码 // 这题让我知道了啥是 gray code // gray code (https://zh.wikipedia.org/wiki/格雷码) // 編碼的方式定義為每個鄰近數字都只相差一個位元,因此也稱為最小差異碼. // 可以使裝置做數字步進時只更動最少的位元數以提高穩定…