# [bzoj1564]二叉查找树

4 10
1 2 3 4
1 2 3 4
1 2 3 4


29

【样例说明】

【数据规模和约定】

 1 // It is made by XZZ
2 #include<cstdio>
3 #include<algorithm>
4 #include<cstring>
5 using namespace std;
6 #define rep(a,b,c) for(rg int a=b;a<=c;a++)
7 #define drep(a,b,c) for(rg int a=b;a>=c;a--)
8 #define erep(a,b) for(rg int a=fir[b];a;a=nxt[a])
9 #define il inline
10 #define rg register
11 #define vd void
12
13 typedef long long ll;
14 il int gi(){
15     rg int x=0;rg char ch=getchar();
16     while(ch<'0'||ch>'9')ch=getchar();
17     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
18     return x;
19 }
20 struct node{ll d,w,n;}a[72];
21 il bool cmp(node kk,node kkk){return kk.w<kkk.w;}
22 il bool cmp2(node kk,node kkk){return kk.d<kkk.d;}
23 ll f[77][77][77];
24 ll num[77];
25 int main(){
26     rg int n=gi();rg ll K=gi();
27     rep(i,1,n)a[i].d=gi();
28     rep(i,1,n)a[i].w=gi(),num[i]=a[i].w;
29     rep(i,1,n)a[i].n=gi();
30     sort(a+1,a+1+n,cmp2);
31     rep(i,1,n)a[i].n+=a[i-1].n;
32     sort(num+1,num+1+n);
33     int mn=unique(num+1,num+1+n)-num-1;
34     rep(i,1,n)a[i].w=lower_bound(num+1,num+1+mn,a[i].w)-num;
35     rep(siz,0,n-1)rep(i,1,n-siz)rep(e,1,mn){
36     ll&now=f[i][i+siz][e];now=2333333333333333333ll;
37     rg int l=i,r=i+siz;
38     rep(k,l,r){
39             if(a[k].w>=e)now=min(now,f[l][k-1][a[k].w]+f[k+1][r][a[k].w]+a[r].n-a[l-1].n);
40         now=min(now,K+f[l][k-1][e]+f[k+1][r][e]+a[r].n-a[l-1].n);
41     }
42     }
43     ll ans=f[1][n][1];
44     rep(i,2,mn)ans=min(ans,f[1][n][i]);
45     printf("%lld\n",ans);
46     return 0;
47 }
View Code

posted @ 2017-07-26 13:15  菜狗xzz  阅读(159)  评论(0编辑  收藏  举报