2015 Multi-University Training Contest 7 hdu 5375 Gray code
2015-08-11 19:29
393 查看
Gray code
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 129 Accepted Submission(s): 68
[align=left]Problem Description[/align]
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.
#include <bits/stdc++.h> using namespace std; const int maxn = 210010; int dp[maxn][2],w[maxn],len; char str[maxn]; int main() { int kase,cs = 1; scanf("%d",&kase); while(kase--) { scanf("%s",str); len = strlen(str); for(int i = 0; i < len; ++i) scanf("%d",w + i); memset(dp,-1,sizeof dp); if(str[0] == '0' || str[0] == '?') dp[0][0] = 0; if(str[0] == '1' || str[0] == '?') dp[0][1] = w[0]; for(int i = 1; i < len; ++i){ if(str[i] == '1' || str[i] == '?'){ if(dp[i-1][1] != -1) dp[i][1] = max(dp[i][1],dp[i-1][1]); if(dp[i-1][0] != -1) dp[i][1] = max(dp[i][1],dp[i-1][0] + w[i]); } if(str[i] == '0' || str[i] == '?'){ if(dp[i-1][0] != -1) dp[i][0] = max(dp[i][0],dp[i-1][0]); if(dp[i-1][1] != -1) dp[i][0] = max(dp[i][0],dp[i-1][1] + w[i]); } } printf("Case #%d: %d\n",cs++,max(dp[len-1][0],dp[len-1][1])); } return 0; }
View Code
相关文章推荐
- Matrix Chain Multiplication
- hdu 4630 No Pain No Game(树状数组)
- 2015 Multi-University Training Contest 7
- [AIR] AS3读取本地文件夹中的文件
- [AIR] AS3读取txt文档
- Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport e
- Container with most water
- main函数中通过使用Person类和AddressBook类,创建对象、调用方法,实现以下8个功能
- Ubuntu下编译运行Kamailio
- AIX开启telnet服务
- POJ 3068 "Shortest" pair of paths(最小费用最大流-mcmf)
- Webmin version 1.760 is now available, but you are running version 1.730.
- 2015 HUAS Summer Trainning #5~A
- Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE的报错的解决方法
- Leetcode -- Container With Most Water
- Leetcode#11||Container With Most Water
- 172 Factorial Trailing Zeroes
- HDU 1532 Drainage Ditches
- SmtpClient发邮件时为什么用MailMessage.From而不用MailMessage.Sender
- MDK __main过程分析