fork(3) download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. #define INF 10000000
  5.  
  6. int dp[25][30],n,h,f,s,a[25],ans,cnt=1,k,i,j;
  7.  
  8. int main()
  9. {
  10. // while(1)
  11. //{
  12. //cin>>n;
  13. n=4;
  14.  
  15. for(int i=0;i<=n;i++)
  16. for(int j=0;j<=n;j++)
  17. if(j>i)dp[i][j]=-INF;
  18. else
  19. dp[i][j]=INF;
  20.  
  21. //if(n==0)
  22. // break;
  23.  
  24. //for(int i=1;i<=n;i++)
  25. // cin>>a[i];
  26. a[1]=1;
  27. a[2]=2;
  28. a[3]=6;
  29. a[4]=10;
  30. //for( i=1;i<=n;i++) dp[i][1]=0;
  31.  
  32. for( i=2;i<=n;i++)
  33. {
  34. cout<<"i = "<<i<<"\n";
  35. int o=-2*INF;
  36. for( j=2;j<=i;j++)
  37. {
  38. cout<<"j = "<<j<<"\n";
  39. for(k=1;k<i;k++)
  40. {
  41. if(k>=j-1)
  42. o= max(o,min(dp[k][j-1],a[i]-a[k]));
  43. //cout<<o<<"\n";
  44. }
  45.  
  46. dp[i][j]=o;
  47. }
  48. }
  49.  
  50. for(i=1;i<=n;i++)
  51. {
  52. cout<<"\n";
  53. for(j=1;j<=n;j++)
  54. cout<<dp[i][j]<<" ";
  55. }
  56.  
  57. //}
  58. cout<<"cgfdshjfckldsgb";
  59. }
  60.  
  61.  
  62.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
i = 2
j = 2
i = 3
j = 2
j = 3
i = 4
j = 2
j = 3
j = 4

10000000 -10000000 -10000000 -10000000 
10000000 1 -10000000 -10000000 
10000000 5 5 -10000000 
10000000 9 9 9 cgfdshjfckldsgb