fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // my choco pie
  5.  
  6. #define ft first
  7. #define sd second
  8. #define pb push_back
  9. #define mp make_pair
  10. #define PII pair<int,int>
  11. #define all(x) x.begin(),x.end()
  12. #define VI vector<int>
  13. #define VII vector<pair<int,int> >
  14. #define VL vector<long long int >
  15. #define VLL vector<pair<long long ,long long > >
  16. #define PLL pair<long long ,long long >
  17. #define itr iterator
  18. #define fill(x,v) fill(all(x),v)
  19.  
  20. // my fastest car series
  21.  
  22. #define scan(x) scanf("%d",&x)
  23. #define print(x) printf("%d\n",x)
  24. #define scanll(x) scanf("%lld",&x)
  25. #define printll(x) printf("%lld\n",x)
  26. #define ms(x) memset(x,0,sizeof(x))
  27.  
  28.  
  29. // data pies
  30.  
  31. #define ll long long int
  32. #define li long int
  33. #define ff float
  34. #define db double
  35.  
  36.  
  37. // loopi loops
  38.  
  39. #define rep(i,a,b) for(i=a;i<b;i++)
  40. #define repr(i,a,b) for(i=a;i>=b;i--)
  41.  
  42.  
  43. // debugger
  44. #define print_v(x) for(int i=0;i<x.size();i++) cout << x[i] << " "
  45. #define debug(x) cout << "#debug" << " " << x << endl
  46.  
  47. #define MOD 1000000007
  48.  
  49. int random_long(int digit=8)
  50. {
  51. int len=digit;
  52. int x=0;
  53. for ( int i = 0; i < len; ++i )
  54. {
  55. int dig = rand() % 10;
  56. while ( x == 0 && dig == 0 )
  57. dig = rand() % 10;
  58. x = x * 10 + dig;
  59. }
  60. return x;
  61. }
  62.  
  63. int random(int l, int r)
  64. {
  65. int diff = r - l + 1;
  66.  
  67. return l+random_long()%diff;
  68.  
  69. }
  70. #define inf INT_MAX/5
  71.  
  72. int main(){
  73.  
  74. int n,k;
  75. cin >> n >> k;
  76. int P[k+1][n+1],i,j,DP[n+5][1<<k];
  77. ms(P),ms(DP);
  78. rep(i,1,k+1)
  79. rep(j,1,n+1)
  80. cin >> P[i][j];
  81. int sz=1<<k,l,m;
  82. rep(i,1,n+1)
  83. rep(j,0,sz)
  84. DP[i][j]=inf;
  85.  
  86. int ans=inf;
  87. repr(i,n,1){
  88. rep(j,0,sz){
  89. rep(l,0,k){
  90. if(!(j&(1<<l))){
  91. int val2=0;
  92. rep(m,i,n+1){
  93. val2+=P[l+1][m];
  94. DP[i][j]=min(DP[i][j],val2+DP[m+1][j|(1<<l)]);
  95. }
  96. }
  97. }
  98. }
  99. }
  100. cout << DP[1][0] << endl;
  101. return 0;
  102. }
Runtime error #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Standard output is empty