Advertisement
sak1b

Untitled

Oct 4th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define MAX(a,b) ((a>b)?a:b)
  4. #define MIN(a,b) ((a<b)?a:b)
  5. #define loop(i, a, b) for(int i=(a);i<=(b);i++)
  6.  
  7. #define pf(x) printf(x);
  8. #define dbg(x) printf("\n--bug: %d --\n",x)
  9. #define PI 2*acos(0.0)
  10. #define all(x) x.begin(),x.end()
  11. #define ll long long
  12. #define pb push_back
  13. #define NL printf("\n")
  14.  
  15.  
  16. using namespace std;
  17. struct items{
  18. int time,des,val,idx;
  19. }a[105];
  20. int n;
  21. int dp[105][2005];
  22. int dir[105][2005];
  23. vector<items> res;
  24. bool cmp(items a,items b)
  25. {
  26. return a.des<b.des;
  27. }
  28.  
  29. bool cmp_idx(items a,items b)
  30. {
  31. return a.idx<b.idx;
  32. }
  33.  
  34. int fun(int item,int clk)
  35. {
  36. //cout<<"working on: "<<item<<" "<<clk<<endl;
  37. if(item>=n) return 0;
  38.  
  39. if(dp[item][clk]!=-1) return dp[item][clk];
  40.  
  41. int profit1=0;
  42. int profit2=0;
  43.  
  44. if((clk+a[item].time) < a[item].des)
  45. {
  46. profit1= a[item].val + fun(item+1,clk+a[item].time);
  47. }
  48. else profit1=0;
  49.  
  50. profit2=fun(item+1,clk);
  51.  
  52. dir[item][clk]=(profit1>profit2)?1:2;
  53.  
  54. return dp[item][clk]=max(profit1,profit2);
  55. }
  56. void solution_print(int item,int clk)
  57. {
  58.  
  59. if(dir[item][clk]==1)
  60. {
  61. res.pb(a[item]);
  62. solution_print(item+1,clk+a[item].time);
  63. }
  64. else if(dir[item][clk]==2)
  65. {
  66. solution_print(item+1,clk);
  67. }
  68. }
  69. int main()
  70. {
  71. freopen("input.txt","r",stdin);
  72. for(int i=0;i<105;i++)
  73. {
  74. for(int j=0;j<2005;j++)
  75. {
  76. dp[i][j]=-1;
  77. dir[i][j]=-1;
  78. }
  79.  
  80. }
  81.  
  82. cin>>n;
  83. loop(i,0,n-1)
  84. {
  85. scanf("%d%d%d",&a[i].time,&a[i].des,&a[i].val);
  86. a[i].idx=i+1;
  87. }
  88.  
  89.  
  90. sort(a,a+n,cmp);
  91. // loop(i,0,n-1) cout<<a[i].time<<" "<<a[i].des<<" "<<a[i].val<<endl;
  92. // NL;
  93. cout<<fun(0,0)<<endl;
  94.  
  95. solution_print(0,0);
  96.  
  97.  
  98. // sort(all(res),cmp_idx);
  99. cout<<res.size()<<endl;
  100. if(res.size()<=0) return 0; ///problem is here
  101. loop(i,0,res.size()-1)
  102. {
  103. printf("%d ",res[i].idx);
  104. }
  105. NL;
  106.  
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement