hdu 4433 locker(DP,4级)
2013-10-07 11:39
246 查看
C - locker
Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status
Appoint description:
System Crawler (2013-09-09)
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
Sample Output
思路:dp+枚举 dp[len][j][k] 前len位,不包含当前位移动到终态,影响i位移动j,i+1位移动k的最优值。
枚举移动影响的两位,当然枚举如果是a,b,c a<=b<=c ,
1000X10X10X10X10
Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d
& %I64u
Submit Status
Appoint description:
System Crawler (2013-09-09)
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
思路:dp+枚举 dp[len][j][k] 前len位,不包含当前位移动到终态,影响i位移动j,i+1位移动k的最优值。
枚举移动影响的两位,当然枚举如果是a,b,c a<=b<=c ,
1000X10X10X10X10
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define FOR(i,a,b) for(int i=a;i<=b;++i) #define clr(f,z) memset(f,z,sizeof(f)) using namespace std; const int mm=1009; const int oo=1e9; char s[mm],t[mm]; int dp[mm][10][10];///前i位OK不包含第i位,i移动j,i+1移动k int main() { while(~scanf("%s%s",s,t)) { int len=strlen(s); FOR(i,0,len)FOR(j,0,9)FOR(k,0,9) dp[i][j][k]=oo; dp[0][0][0]=0; FOR(i,0,len-1) { FOR(j,0,9)FOR(k,0,9) { if(dp[i][j][k]==oo)continue; // puts("yes"); int zk=(t[i]-s[i]-j+30)%10; FOR(a,0,zk)FOR(b,0,a)///正转 dp[i+1][(k+a)%10][b]=min(dp[i+1][(k+a)%10][b],dp[i][j][k]+zk); zk=10-zk; ///逆转 FOR(a,0,zk)FOR(b,0,a) 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]+zk); // cout<<dp[i+1][0][0]<<endl; } } printf("%d\n",dp[len][0][0]); } }
相关文章推荐
- hdu 4433 locker(DP,4级)
- [HDU 4433]locker[DP]
- HDU 4433 locker(DP)
- HDU 4433 locker(DP)( UVA 1631 - Locker)
- HDU 4433 locker(SPFA+DP)
- HDU 4433 locker(三维dp)
- HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)
- HDU 4433 locker(12年天津,DP)
- Hdu 4433 locker【思维+Dp】
- HDU 4433 locker 状态压缩DP
- hdu 4433(uva1631) - Locker - dp
- hdu 4433 locker (dp)
- hdu 4433 locker(DP)
- HDU 4433 locker (线性dp)
- HDU 4433 locker 2012 Asia Tianjin Regional Contest 减少国家DP
- UVA 1631 Locker(HDU 4433)(DP)
- HDU 4433 locker(12年天津,DP)
- [HDU 4433]locker[DP]
- hdu 4433 locker(DP)
- hdu 4362 Dragon Ball(DP+优化,4级)