先上题目:
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 2145 Accepted
Submission(s): 726
1 #include <cstdio> 2 #include <cstring> 3 #define min(x,y) (x <= y ? x : y) 4 #define MAX 102 5 #define INF 0x0fffffff 6 using namespace std; 7 8 int dp[MAX*MAX][17]; 9 int c[2][MAX]; 10 11 int main() 12 { 13 int l,n,m,minn; 14 //freopen("data.txt","r",stdin); 15 while(scanf("%d %d",&l,&n)!=EOF){ 16 for(int i=0;i<=1;i++){ 17 for(int j=0;j<l;j++){ 18 scanf("%d",&c[i][j]); 19 } 20 } 21 m=l*n; 22 for(int i=1;i<=m;i++){ 23 for(int j=0;j<15;j++){ 24 dp[i][j]=INF; 25 } 26 } 27 dp[1][1]=c[0][0]; 28 for(int i=1;i<m;i++){ 29 for(int j=0;j<15;j++){ 30 int k=j+1; 31 if(k==15) k=10; 32 dp[i+1][k]=min(dp[i+1][k],dp[i][j]+c[0][i%l]); 33 34 if(j>=5) 35 dp[i+1][j-5]=min(dp[i+1][j-5],dp[i][j]+c[1][i%l]); 36 } 37 } 38 minn=INF; 39 for(int i=0;i<15;i++){ 40 minn=min(minn,dp[m][i]); 41 } 42 printf("%d\n",minn); 43 } 44 return 0; 45 }
HDU - 1494 - 跑跑卡丁车,布布扣,bubuko.com
原文:http://www.cnblogs.com/sineatos/p/3626833.html