标签:std wan scan tin 第一个 esc efi mini integer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define esp 0.00000000001 5 struct node 6 { 7 ll x; 8 ll c; 9 } N[3005]; 10 bool cmp(struct node a,struct node b) 11 { 12 return a.x<b.x; 13 } 14 ll dp[3005][5]; 15 ll sum[3005]; 16 int main() 17 { 18 int n; 19 while(scanf("%d",&n)!=EOF) 20 { 21 for(int i=1; i<=n; i++) 22 scanf("%I64d %I64d",&N[i].x,&N[i].c); 23 sort(N+1,N+1+n,cmp); 24 for(int i=1; i<=n; i++) 25 { 26 dp[i][1]=5e18; 27 dp[i][2]=5e18; 28 } 29 dp[0][1]=0; 30 dp[0][2]=0; 31 for(int i=1; i<=n; i++) 32 { 33 dp[i][1]=min(dp[i-1][1],dp[i-1][2])+N[i].c; 34 ll exm=0; 35 for(int j=i-1; j>=1; j--) 36 { 37 exm=exm+(i-j)*(N[j+1].x-N[j].x);//累加距离 38 dp[i][2]=min(dp[i][2],dp[j][1]+exm); 39 } 40 } 41 printf("%I64d\n",min(dp[n][1],dp[n][2])); 42 } 43 return 0; 44 }
2017中国大学生程序设计竞赛 - 女生专场 1002 dp
标签:std wan scan tin 第一个 esc efi mini integer
原文地址:http://www.cnblogs.com/hsd-/p/6821352.html