标签:set scan cli hellip inpu size back hang ann
【样例1】
36
【样例2】
91
【样例3】
314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170
【样例1】
8
【样例2】
3
【样例3】
243
一道dp,对于某一种纸币,假如需要支付x张,可以支付x张或10-x张+一张大一级的纸币。
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 using namespace std; 5 const int N =1000009; 6 typedef long long LL; 7 char c[N]; 8 int f[N][2]; 9 int n; 10 int main() 11 { 12 memset(f, 0x3f, sizeof(f)); 13 scanf("%s", c + 1); 14 n = strlen(c + 1); 15 f[n][0] = c[n] - ‘0‘; 16 f[n][1] = 10 - (c[n] - ‘0‘); 17 c[0] = ‘0‘; 18 for(int i = n - 1; i >= 0; i--) 19 f[i][0] = min(f[i+1][0] + c[i] - ‘0‘, f[i+1][1] + c[i] - ‘0‘ +1), 20 f[i][1] = min(f[i+1][0] + 10 - (c[i] - ‘0‘), f[i+1][1] + 10 - (c[i] - ‘0‘ + 1)); 21 printf("%d\n",min(f[0][0], f[0][1])); 22 return 0; 23 }
标签:set scan cli hellip inpu size back hang ann
原文地址:https://www.cnblogs.com/Jony-English/p/12494356.html