locker

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1271    Accepted Submission(s): 549

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?

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.

Output
For each case, output one integer, the minimum amount of steps from the current state to the secret password.

Sample Input
111111 222222 896521 183995

Sample Output
2 12

Source

Recommend
zhoujiaqi2010   |   We have carefully selected several similar problems for you:  4812 4811 4810 4809 4808

f[i,j,k] 表示第i格已经扳到j，i+1格已经扳到k。前i-1个格子都到指定位置。的最小转动次数。

（注意k和a的含义不同，j和t的含义也不同。因为j和k是之前被动地转，a是当前i+1被动地转，t是i主动在转）

1、无序有序化，有时就可以消除后效性（当然要利用一些手段比如整体看待）。
2、有多少元素参与转移，常常就会有多少元素在转移方程里，把它们当做一个整体来看待。

#include <cstdio>
#include <cstring>

int min(int a,int b)
{
return a<b?a:b;
}

int f[1010][10][10];
char s1[1010];
char s2[1010];

int main()
{
while (scanf("%s%s",s1,s2)!=EOF)
{
int len = strlen(s1);

memset(f,0x3f,sizeof f);
f[0][0][0] = 0;
for (int i=0;i<len;i++)
{
for (int j=0;j<10;j++)
{
for (int k=0;k<10;k++)
{
int t = (s2[i]-s1[i]-j+20)%10;
for (int a=0;a<=t;a++)
{
for (int b=0;b<=a;b++)
{
f[i+1][(k+a)%10][b] = min(f[i+1][(k+a)%10][b],f[i][j][k]+t);
}
}

t = 10-t;
for (int a=0;a<=t;a++)
{
for (int b=0;b<=a;b++)
{
f[i+1][(k-a+20)%10][(10-b)%10] = min(f[i+1][(k-a+20)%10][(10-b)%10],f[i][j][k]+t);
}
}
}
}
}
printf("%d\n",f[len][0][0]);

}
return 0;
}

联想 Lenovo Port Locker 给USB接口加上密码保护

2012年04月07日 13.57MB 下载

Linux之软件包管理

2016-08-24 19:57:33

Easy File Locker

2009年10月05日 301KB 下载

Easy File Locker 文件隐藏 保护

2016年07月27日 969KB 下载

QMutexLocker

2013-08-20 09:20:04

SOJ. Locker puzzle

2015-01-16 23:10:26

QMutex QMutexLocker简单实例应用

2017-08-16 13:45:04

locker源码

2016年03月04日 14.57MB 下载

QMutexLocker作用范围

2017-11-08 13:14:13