[Wqs half || decision monotonic] cf321E. Ciel and Gondolas

As the state of layers, each decision-making process monotonicity

Title Description

Subject to the effect

As we all know, Chen fish is a highly intelligent aquatic animals. But they came to the land IQ will be halved.
This is not? They're in big trouble!
n Only Chen fish to travel on land, there are k cars can be rented.
Since Chen fish who can not walk freely on land, a car carrying only a contiguous Chen fish.
Chen fish who have a deep resentment of each other, each have grievances value between Chen fish.
Only the i-th and the j fish Chen Chen only referred to as value fish anger Yij, and Yij = Yji, Yii = 0.
Each vehicle load is not limited, but each produces resentment in the value of the same car will Jeong fish.
Of course, the Super Seniors Chen fish zzp minimum value of the sum of grievances.
But his IQ has halved, I can not think of allocation scheme.
Now he found you, you have to help him allocation Chen fish, and the minimum output value of grievances and ans.
n <= 4000,1 ≤ k ≤min ( n, 800)


 

Topic analysis

A practice: wqs half

The question at first glance like a wqs half, and the answer is really a function of the shape of a convex function.

So first and foremost a wqs half of the template title.

 1 #include<bits/stdc++.h>
 2 typedef long long ll;
 3 const int maxn = 4035;
 4 const int INF = 0x3f3f3f3f;
 5 
 6 int n,k,L,R;
 7 ll a[maxn][maxn],g[maxn][maxn],f[maxn],h[maxn],ans;
 8 
 9 char tc(){static char tr[1000000],*A=tr,*B=tr;return A==B&&(B=(A=tr)+fread(tr,1,1000000,stdin),A==B)?EOF:*A++;}
10 #define getchar tc
11 int read()
12 {
13     char ch = getchar();
14     int num = 0, fl = 1;
15     for (; !isdigit(ch); ch=getchar())
16         if (ch=='-') fl = -1;
17     for (; isdigit(ch); ch=getchar())
18         num = (num<<1)+(num<<3)+ch-48;
19     return num*fl;
20 }
21 ll check(int w)
22 {
23     memset(f, 0x3f3f3f3f, sizeof f);
24     memset(h, 0x3f3f3f3f, sizeof h);
25     f[0] = h[0] = 0;
26     for (int i=1; i<=n; i++)
27         for (int j=0; j<i; j++)
28             if (f[i] > f[j]+g[j+1][i]+w||(f[i]==f[j]+g[j+1][i]+w&&h[j]+1 < h[i])){
29                 f[i] = f[j]+g[j+1][i]+w, h[i] = h[j]+1;
30             }
31     if (h[n] <= k) ans = f[n]-k*w;
32     return h[n];
33 }
34 int main()
35 {
36     n = read(), k = read();
37     for (int i=1; i<=n; i++)
38         for (int j=1; j<=n; j++) a[i][j] = read();
39     for (int i=n; i>=1; i--)
40         for (int j=i; j<=n; j++)
41             g[i][j] = g[i+1][j]+g[i][j-1]-g[i+1][j-1]+a[i][j];
42     ans = INF, L = 0, R = g[1][n];
43     for (int mid=(L+R)>>1; L<=R; mid=(L+R)>>1)
44         if (check(mid) <= k) R = mid-1;
45         else L = mid+1;
46     printf("%lld\n",ans);
47     return 0;
48 }

Practice two: Decision monotonic

$ N ^ 2 $ dp is $ f [j] [i] $ $ I $ represents the front fish into a minimum cost $ $ J groups. For each same $ j $, which is monotonic in the transfer. That is the $ i $ regarded as a layer, and the rest is transferred between the layers.

Temporarily not write.

 

END

Guess you like

Origin www.cnblogs.com/antiquality/p/11311625.html