#include <iostream>
using namespace std;
#define MAX_N 8010
#define OFFICE_MEETING 1
#define REMOTE_MEETING 2
#define FREE_TIME 3
// [currnet_hour][ommited_meeteings]
// 0 hour - pre harmonogram
int office[MAX_N][MAX_N];
int home[MAX_N][MAX_N];
int harmonogram[MAX_N];
int n, k, t;
void update_office(int h, int om, int new_val)
{
if (om > k)
return;
if (office[h][om] < new_val)
office[h][om] = new_val;
}
void update_home(int h, int om, int new_val)
{
if (om > k)
return;
if (home[h][om] < new_val)
home[h][om] = new_val;
}
int main() {
cin >> n >> k >> t;
for(int i = 0; i < n; i++)
{
char c;
cin >> c;
harmonogram[i] = c - '0';
}
for(int i = 0; i < n+1; i++)
{
for(int j = 0; j < k+1; j++)
{
office[i][j] = -1;
home[i][j] = -1;
}
}
home[0][0] = 0;
int cost_of_travel = 0;
for (int i = 0; i < t; i++)
{
if (harmonogram[i] != FREE_TIME)
cost_of_travel++;
}
for(int i = 0; i < n; i++) // source hour
{
for(int j = 0; j < k+1; j++) // source ommited
{
// home scenarion
if (home[i][j] != -1)
{
int current_val = home[i][j];
// contest in free time
if (harmonogram[i] == FREE_TIME)
update_home(i+1, j, current_val+1);
else // contest in meeteing time
update_home(i+1, j+1, current_val+1);
// remote meeteing
if (harmonogram[i] == REMOTE_MEETING)
update_home(i+1, j, current_val);
// traveling to office
if (i+t < n+1)
update_office(i+t, j+cost_of_travel, current_val);
}
// office scenario
if (office[i][j] != -1)
{
int current_val = office[i][j];
// working
update_office(i+1, j, current_val);
// traveling to home
if (i+t < n+1)
update_home(i+t, j+cost_of_travel, current_val);
}
}
if (harmonogram[i] != FREE_TIME)
cost_of_travel--;
if (i+t < n && harmonogram[i+t] != FREE_TIME)
cost_of_travel++;
}
int sol = home[n][0];
for (int i = 1; i < k+1; i++)
if (sol < home[n][i])
sol = home[n][i];
cout << sol;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #include <iostream> using namespace std; #define MAX_N 8010 #define OFFICE_MEETING 1 #define REMOTE_MEETING 2 #define FREE_TIME 3 // [currnet_hour][ommited_meeteings] // 0 hour - pre harmonogram int office[MAX_N][MAX_N]; int home[MAX_N][MAX_N]; int harmonogram[MAX_N]; int n, k, t; void update_office(int h, int om, int new_val) { if (om > k) return; if (office[h][om] < new_val) office[h][om] = new_val; } void update_home(int h, int om, int new_val) { if (om > k) return; if (home[h][om] < new_val) home[h][om] = new_val; } int main() { cin >> n >> k >> t; for(int i = 0; i < n; i++) { char c; cin >> c; harmonogram[i] = c - '0'; } for(int i = 0; i < n+1; i++) { for(int j = 0; j < k+1; j++) { office[i][j] = -1; home[i][j] = -1; } } home[0][0] = 0; int cost_of_travel = 0; for (int i = 0; i < t; i++) { if (harmonogram[i] != FREE_TIME) cost_of_travel++; } for(int i = 0; i < n; i++) // source hour { for(int j = 0; j < k+1; j++) // source ommited { // home scenarion if (home[i][j] != -1) { int current_val = home[i][j]; // contest in free time if (harmonogram[i] == FREE_TIME) update_home(i+1, j, current_val+1); else // contest in meeteing time update_home(i+1, j+1, current_val+1); // remote meeteing if (harmonogram[i] == REMOTE_MEETING) update_home(i+1, j, current_val); // traveling to office if (i+t < n+1) update_office(i+t, j+cost_of_travel, current_val); } // office scenario if (office[i][j] != -1) { int current_val = office[i][j]; // working update_office(i+1, j, current_val); // traveling to home if (i+t < n+1) update_home(i+t, j+cost_of_travel, current_val); } } if (harmonogram[i] != FREE_TIME) cost_of_travel--; if (i+t < n && harmonogram[i+t] != FREE_TIME) cost_of_travel++; } int sol = home[n][0]; for (int i = 1; i < k+1; i++) if (sol < home[n][i]) sol = home[n][i]; cout << sol; return 0; } |
English