标签:uri ace namespace 输入 int log code white ccf
题目描述:(DP问题)
1 #include <iostream> 2 using namespace std; 3 //dp[i] = min(dp[i],dp[i-a[j]+1) 4 5 int main() 6 { 7 int sum; 8 while(cin>>sum) 9 { 10 int a[2] = {6,8}; 11 int dp[100]; 12 dp[0] = 0;//也是关键之处 13 for(int i=1;i<100;i++) 14 { 15 dp[i] = sum; 16 } 17 for(int i=0;i<=sum;i++) 18 { 19 for(int j=0;j<2;j++) 20 { 21 if(i>=a[j] && dp[i-a[j]] + 1 < dp[i]) 22 { 23 dp[i] = dp[i-a[j]]+1; 24 } 25 } 26 } 27 if(dp[sum] == sum) 28 cout<<-1<<endl; 29 else 30 cout<<dp[sum]<<endl; 31 return 0; 32 } 33 }
标签:uri ace namespace 输入 int log code white ccf
原文地址:http://www.cnblogs.com/qqky/p/6796061.html