fork download
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. int N, x, T, K, price[101], lvl, totalLvl[101];
  6. int memo[101][1200][26];
  7. double money;
  8.  
  9. int count(int dim, int harga, int qty){
  10. int hasil;
  11. // cout<<"harga "<<harga<<endl;
  12. double totalPrice = harga + (harga*0.1);
  13. if(dim==K&&qty>=0) return 0;
  14. if(totalPrice>=money) return 0;
  15. if(qty<=0) return 0;
  16. // cout<<"total "<<totalPrice<<endl;
  17. if(memo[dim][harga][qty]!=-1) return memo[dim][harga][qty];
  18. if((totalPrice+(price[dim]+(price[dim]*0.1)))>=money) return hasil = count(dim+1, harga, qty);
  19. if((totalPrice+((price[dim]*2)+(price[dim]*2*0.1)))>=money||qty==1) return hasil = max(count(dim+1, harga, qty), count(dim+1, harga+price[dim], qty-1)+totalLvl[dim]);
  20. hasil = max(count(dim+1, harga, qty), count(dim+1, harga+price[dim], qty-1)+totalLvl[dim]);
  21. hasil = max(hasil, count(dim+1, harga+(price[dim]*2), qty-2)+(totalLvl[dim]*2));
  22. // cout<<"count "<<hasil<<endl;
  23. return memo[dim][harga][qty] = hasil;
  24. }
  25.  
  26. int main(){
  27.  
  28. double hasil;
  29.  
  30. while(cin>>N>>x>>T>>K){
  31. if(N==0&&x==0&&T==0&&K==0) break;
  32. N+=1;
  33. for(int i=0;i<101;i++){
  34. for(int j=0;j<1200;j++){
  35. for(int k=0;k<26;k++){
  36. memo[i][j][k] = -1;
  37. }
  38. }
  39. }
  40. for(int i=0; i<101; i++){
  41. totalLvl[i]=0;
  42. }
  43. for(int i=0; i<K; i++){
  44. cin>>price[i];
  45. for(int j=0; j<N; j++){
  46. cin>>lvl;
  47. totalLvl[i]+=lvl;
  48. }
  49. }
  50. money = N*x;
  51. // cout<<"awal "<<money<<endl;
  52. money = money - ((N*T)+((N*T)*0.1));
  53. hasil = count(0, 0, N*2);
  54. // cout<<"OK "<<money<<endl;
  55. // cout<<"hasil "<<hasil<<endl;
  56. double mean = hasil/N;
  57. // cout<<"mean "<<mean<<endl;
  58. cout<<fixed<<setprecision(2)<<mean<<endl;
  59. }
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0s 27544KB
stdin
3 9 3 2
4 7 5 6 9
10 2 1 3 8

3 10 5 2
6 7 5 6 9
10 9 10 10 8

3 100 1 2
1 10 10 10 10
2 10 10 10 10


9 4 3 2
4 2 0 0 0 0 0 0 0 0 0 
10 1 0 0 0 0 0 0 0 0 0

3 10 5 2
6 7 5 6 9
10 9 10 10 8
3 10 5 2
6 7 5 6 9
10 9 10 2 8
3 10 5 2
6 7 5 6 9
10 2 1 3 8


3 10 0 3
6 0 0 0 0
10 9 10 10 8
7 10 10 10 10


5 10 0 1
10 1 1 1 1 1 2

5 100 0 10
10 0 0 0 0 0 1
10 0 0 0 0 2 3
10 0 0 0 0 0 0
10 0 1 2 0 0 0
10 0 10 4 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 10 0 0 0
10 0 0 0 5 0 1
10 0 0 0 0 5 5


5 100 0 10
10 0 0 0 0 0 1
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 0
10 0 0 0 0 0 1


9 100 20 10
9 2 4 10 1 9 1 5 9 6 4
1 3 5 5 5 5 6 3 10 4 9
4 2 2 1 0 8 3 3 4 8 1
4 7 10 3 1 1 7 6 8 8 1
4 6 3 2 2 9 2 6 7 1 8
10 8 9 7 1 3 7 4 9 9 7
7 3 5 1 2 1 8 2 4 4 4
6 6 2 7 2 3 5 0 5 4 7
7 10 5 3 6 2 7 4 4 7 7
7 5 2 5 8 4 8 1 4 8 8

9 100 20 12
9 2 4 10 1 9 1 5 9 6 4
1 3 5 5 5 5 6 3 10 4 9
4 2 2 1 0 8 3 3 4 8 1
4 7 10 3 1 1 7 6 8 8 1
4 6 3 2 2 9 2 6 7 1 8
10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