3810: [Coci2015]Stanovi
Time Limit: 15 Sec Memory Limit: 64 MBSubmit: 650 Solved: 302
[ Submit][ Status][ Discuss]
Description
Input
输入一行,三个整数,n, m, k
Output
输出一个数,表示最小不满意度。
Sample Input
3 3 2
Sample Output
1
【Hint】
见描述中的左图的分割方案,最小不满意度为4 * (2 - 2) ^ 2 + (1 - 2) ^ 2 = 1。
【数据范围】
n, m <= 300
k <= 10000
【Hint】
见描述中的左图的分割方案,最小不满意度为4 * (2 - 2) ^ 2 + (1 - 2) ^ 2 = 1。
【数据范围】
n, m <= 300
k <= 10000
HINT
Source
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<stack>
#define min(a,b) ((a) < (b) ? (a) : (b))
using namespace std;
const int N = 303;
typedef long long LL;
int n,m,k;
bool vis[N][N][2][2][2][2];
LL f[N][N][2][2][2][2];
inline LL Dfs(int N,int M,int l,int r,int u,int d)
{
if (N > M) swap(N,M),swap(u,l),swap(d,r);
if (u && !d) swap(u,d); if (l && !r) swap(l,r);
if (vis[N][M][l][r][u][d]) return f[N][M][l][r][u][d];
f[N][M][l][r][u][d] = 1LL * (N * M - k) * (N * M - k);
if (u || d || (l && r))
for (int i = 1; i < M; i++)
f[N][M][l][r][u][d] = min(f[N][M][l][r][u][d],Dfs(N,i,l,0,u,d) + Dfs(N,M - i,0,r,u,d));
if (l || r || (u && d))
for (int i = 1; i < N; i++)
f[N][M][l][r][u][d] = min(f[N][M][l][r][u][d],Dfs(i,M,l,r,u,0) + Dfs(N - i,M,l,r,0,d));
vis[N][M][l][r][u][d] = 1; return f[N][M][l][r][u][d];
}
int main()
{
#ifdef DMC
freopen("DMC.txt","r",stdin);
#endif
cin >> n >> m >> k;
cout << Dfs(n,m,1,1,1,1) << endl;
return 0;
}