简单dp --- HDU1248寒冰王座
这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350])
代码如下:
1 #include<iostream> 2 #include <stdio.h> 3 using namespace std; 4 int dp[10010]; 5 int main() 6 { 7 for (int i = 0; i < 150; i++) 8 dp[i] = i; 9 for (int i = 151; i < 10010; i++) 10 { 11 int minn; 12 if (i < 200) 13 dp[i] = dp[i - 150]; 14 else if (i < 350) 15 dp[i] = min(dp[i - 150], dp[i - 200]); 16 else 17 { 18 19 minn = min(dp[i - 150], dp[i - 200]); 20 minn = min(minn, dp[i - 350]); 21 dp[i] = minn; 22 } 23 } 24 int t; 25 scanf("%d", &t); 26 while (t--) 27 { 28 int n; 29 scanf("%d", &n); 30 printf("%d\n", dp[n]); 31 } 32 33 return 0; 34 }