Untitled
unknown
plain_text
2 years ago
2.7 kB
19
Indexable
#include <stdio.h> /*---------------------Init Variable--------------------*/ int Answer; int num_person; int person[52][2]; int temp; int score_person[52]; int time_adv_of_person[52][4]; int matrix[52][52]; int count[52]; int list_adv[4][2]; int list_adv_show[4][2]; int check_adv[4]; int time[52]; int max_time; int min_time; int flag, flag2; int temp_score; int Score; int score(){ temp_score = 0; for(int i = 1; i <= num_person; i++){ for(int adv = 1; adv <= 3; adv++){ if(person[i][0] <= list_adv_show[adv][0] && person[i][1] >= list_adv_show[adv][1]){ if(list_adv[adv][1] > score_person[i]) score_person[i] = list_adv[adv][1]; } } temp_score += score_person[i]; score_person[i] = 0; } return temp_score; } void solve( int step, int k){ if(step == 3){ Score = score(); if(Score > Answer) Answer = Score; return; } if(check_adv[k] == 0){ check_adv[k] = 1; for(int i = min_time; i <= max_time - list_adv[k][0]; i++){ flag = flag2 = 0; for(int j = i; j < i+list_adv[k][0]; j++){ if(time[j] != 0){ flag = 1; break; } } if(i == max_time - list_adv[k][0] && flag == 1) flag2 = 1; if(flag == 1) continue; for(int j = i; j < i+list_adv[k][0]; j++){ time[j] = k; } list_adv_show[k][0] = i; list_adv_show[k][1] = i + list_adv[k][0] ; solve(step + 1, k +1); list_adv_show[k][0] = 0; list_adv_show[k][1] = 0; for(int j = i; j < i+list_adv[k][0]; j++){ time[j] = 0; } } if(flag2 == 1) solve(step + 1, k + 1); check_adv[k] = 0; } } int main(void) { int test_case; int T; freopen("input.txt", "r", stdin); setbuf(stdout, NULL); scanf("%d", &T); for (test_case = 1; test_case <= T; ++test_case) { Answer = 0; max_time = 0; min_time = 100000; scanf("%d %d %d %d %d %d %d", &num_person, &list_adv[1][0], &list_adv[2][0], &list_adv[3][0], &list_adv[1][1], &list_adv[2][1], &list_adv[3][1]); for(int i = 1; i <= num_person; i++){ scanf("%d %d", &person[i][0], &temp); person[i][1] = person[i][0] + temp; if(person[i][1] > max_time) max_time = person[i][1]; if(person[i][0] < min_time) min_time = person[i][0]; } for(int i = 1; i < max_time; i++){ for(int j = 1; j <= num_person; j++){ matrix[j][i] = 0; } } for(int i = 1; i < max_time; i++){ for(int j = 1; j <= num_person; j++){ if(i < person[j][1] && i >= person[j][0]){ matrix[j][i] = 1; } } } solve(0,1); printf("Case #%d\n%d\n",test_case,Answer); } return 0; }
Editor is loading...