fork download
  1. //Lib
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<ctime>
  7.  
  8. #include<iostream>
  9. #include<algorithm>
  10. #include<vector>
  11. #include<string>
  12. #include<queue>
  13. #include<stack>
  14. #include<set>
  15. #include<map>
  16. using namespace std;
  17. //Macro
  18. #define rep(i,a,b) for(int i=a,tt=b;i<=tt;++i)
  19. #define drep(i,a,b) for(int i=a,tt=b;i>=tt;--i)
  20. #define erep(i,e,x) for(int i=x;i;i=e[i].next)
  21. #define irep(i,x) for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
  22. #define read() (strtol(ipos,&ipos,10))
  23. #define sqr(x) ((x)*(x))
  24. #define pb push_back
  25. #define PS system("pause");
  26. typedef long long ll;
  27. typedef pair<int,int> pii;
  28. const int oo=~0U>>1;
  29. const double inf=1e100;
  30. const double eps=1e-6;
  31. string name="", in=".in", out=".out";
  32. //Var
  33. int n,m,K;
  34. int s[3][108];
  35. int f[11][108][108];
  36. void Init()
  37. {
  38. scanf("%d%d%d",&n,&m,&K);
  39. rep(i,1,n)rep(j,1,m)scanf("%d",&s[j][i]),s[j][i]+=s[j][i-1];
  40. }
  41. int Calc()
  42. {
  43. rep(k,1,K)rep(i,1,n)
  44. {
  45. f[k][i][0]=f[k][i-1][0];
  46. rep(j,0,i-1)
  47. f[k][i][0]=max(f[k][i][0],f[k-1][j][0]+s[1][i]-s[1][j]);
  48. }
  49. return f[K][n][0];
  50. }
  51. void Work()
  52. {
  53. if(m==1){cout<<Calc()<<endl;return;}
  54. rep(k,1,K)rep(i,1,n)rep(j,1,n)
  55. {
  56. f[k][i][j]=max(f[k][i-1][j],f[k][i][j-1]);
  57. rep(l,0,i-1)
  58. f[k][i][j]=max(f[k][i][j],f[k-1][l][j]+s[1][i]-s[1][l]);
  59. rep(l,0,j-1)
  60. f[k][i][j]=max(f[k][i][j],f[k-1][i][l]+s[2][j]-s[2][l]);
  61. if(i==j)
  62. {
  63. rep(l,0,i-1)
  64. f[k][i][j]=max(f[k][i][j],f[k-1][l][l]+s[1][i]-s[1][l]+s[2][j]-s[2][l]);
  65. }
  66. }
  67. cout<<f[K][n][n]<<endl;
  68. }
  69. int main()
  70. {
  71. // freopen((name+in).c_str(),"r",stdin);
  72. // freopen((name+out).c_str(),"w",stdout);
  73. Init();
  74. Work();
  75. return 0;
  76. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty