hdu4433 locker 密码锁(枚举)
来源:互联网 发布:软件产品与软件服务 编辑:程序博客网 时间:2024/05/29 18:33
locker
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 883 Accepted Submission(s): 374
Problem Description
A password locker with N digits, each digit can be rotated to 0-9 circularly.
You can rotate 1-3 consecutive digits up or down in one step.
For examples:
567890 -> 567901 (by rotating the last 3 digits up)
000000 -> 000900 (by rotating the 4th digit down)
Given the current state and the secret password, what is the minimum amount of steps you have to rotate the locker in order to get from current state to the secret password?
You can rotate 1-3 consecutive digits up or down in one step.
For examples:
567890 -> 567901 (by rotating the last 3 digits up)
000000 -> 000900 (by rotating the 4th digit down)
Given the current state and the secret password, what is the minimum amount of steps you have to rotate the locker in order to get from current state to the secret password?
Input
Multiple (less than 50) cases, process to EOF.
For each case, two strings with equal length (≤ 1000) consists of only digits are given, representing the current state and the secret password, respectively.
For each case, two strings with equal length (≤ 1000) consists of only digits are given, representing the current state and the secret password, respectively.
Output
For each case, output one integer, the minimum amount of steps from the current state to the secret password.
Sample Input
111111 222222896521 183995
Sample Output
212
Source
2012 Asia Tianjin Regional Contest
dp[i][j][k]表示 前i个已经完全匹配,而这时候,第i+1个已经加了j位,第i+2位已经加了k
转移分为两步,枚举加,枚举减
注意如果第i位加了a,第i+1位加了b,第i+2位加了c,那么a>=b>=c这个关系不能错
#include<stdio.h>#include<string.h>#define inf 1000000000;int dp[1005][10][10];int min(int x,int y){return x<y?x:y;}int main(){int i,j,k,l,a,c,b,len;char s1[1005],s2[1005];while(scanf("%s%s",s1,s2)!=EOF){len=strlen(s1);for(i=0;i<=len;i++)for(j=0;j<10;j++)for(k=0;k<10;k++)dp[i][j][k]=inf;dp[0][0][0]=0;for(i=0;i<len;i++)for(j=0;j<10;j++)for(k=0;k<10;k++){c=(20+s2[i]-s1[i]-j)%10;//向上for(a=0;a<=c;a++)for(b=0;b<=a;b++){dp[i+1][(k+a)%10][b]=min(dp[i+1][(k+a)%10][b],dp[i][j][k]+c);//最多需要c步。//当前状态的k到了i+1状态时到了对应的j位置}c=(10-c)%10;//向下for(a=0;a<=c;a++)for(b=0;b<=a;b++){dp[i+1][(k-a+10)%10][(10-b)%10]=min(dp[i+1][(k-a+10)%10][(10-b)%10],dp[i][j][k]+c);}}printf("%d\n",dp[len][0][0]);}return 0;}
- hdu4433 locker 密码锁(枚举)
- HDU4433 Locker(DP)
- hdu4433 locker(dp)
- hdu4433 locker
- hdu4433 locker
- hdu4433 locker
- UVa 1631 Locker (密码锁)
- hdu4433 locker
- 枚举之特殊密码锁
- 枚举-OpenJudge-8469-特殊密码锁
- hdu 4433 locker(动态规划:枚举状态)
- 042day(OJ枚举例题(特殊密码锁)的练习)
- 神奇密码锁 BFS (枚举) 进位转换 memcmp
- 神奇密码锁(BFS)
- 密码锁(3602017秋招真题)
- 密码锁
- 密码锁
- HDU 4433 locker(DP)( UVA 1631 - Locker)
- Linux系统学习笔记:运行程序
- 【C++沉思录】strcpy的实现
- 精 挑 细 选
- liunx学习笔记之--档案与文件系统的压缩与打包
- CSS之Position详解
- hdu4433 locker 密码锁(枚举)
- Windows Phone 设置全屏&&设置竖屏坐标系
- Linux系统学习笔记:信息的表示
- c语言和vc对文件的操作的异同
- libpcap(source : http://blog.csdn.net/htttw/article/details/7521053)
- Minimum Inversion Number
- Spring的AOP
- using namespace std
- linux 基础教程地址(centos)