2009_Round_1C_C

来源:互联网 发布:系统 数据库备份策略 编辑:程序博客网 时间:2024/06/03 22:42
//bribe the prisoners
//http://blog.csdn.net/lizo_is_me/article/details/43735509
//compute the sub item first , then left_cost+right_cost+item(i->j)-1 =>cost of bribe i->j
//dp+iterate
//bribe the prisoners//http://blog.csdn.net/lizo_is_me/article/details/43735509//compute the sub item first , then left_cost+right_cost+item(i->j)-1 =>cost of bribe i->j//dp+iterate#include<iostream>#define inf 0x7fffffffusing namespace std;int a[maxn+10],cost[maxn+10][maxn+10];void  solve(){  a[0]=0,a[n+1]=n+1;  for(int i=0;i<n+1;i++){    cost[i][i+1]=0;  }  for(int w=2;w<=n+1;w++){    for(int i=0;i+w<=n+1;i++){      int j=i+w,temp=inf;      for(int k=i+1;k<j;k++){        temp=min(temp,cost[i][k]+cost[k][j]);      }      cost[i][j]=temp+a[j]-a[i]-1-1;  //first for a[j]-a[i]-1(not include border),the other for minus itself    }  }  cout<<cost[0][n+1];}


0 0