题意: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?
#include#include #include #include #define maxn 1100 #define inf 1000000 using namespace std; char s1[maxn]; char s2[maxn]; int a[maxn]; int b[maxn]; int up[12][12]; int down[12][12]; int dp[maxn][12][12]; int n; void init() { int i,j; for(i=0;i<=9;i++) { for(j=0;j<=9;j++) { up[i][j]=j>=i?j-i:10+(j-i); down[i][j]=j<=i?i-j:10+i-j; } } } int main() { init(); int i,j,k; int ii,jj; while(~scanf("%s %s",&s1, &s2)) { n = strlen(s1); for(i=0;i<=n+3;i++) { for(j=0;j<=9;j++) { for(k=0;k<=9;k++) { dp[i][j][k]=inf; } } } for(i=0; i