天天看點

1050房間桌椅轉移

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;//這是區間最大重載數問題 
int main() {
	int t, n, count[410], i, start, end, k;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		memset(count, 0, sizeof(count));
		while (n--) {
			scanf("%d%d", &start, &end);
			//可能出發位置比目的地房間大。
			if (start>end) {
				//無論大小,我們都可以看做從小的房間移動到大的房間
				k = start;
				start = end;
				end = k;
			}
			if (start % 2 == 0)//考慮實際情況,出發房間為偶數是減一,可參照題中給出的圖一,不統一無法實作對于走廊dp
				start -= 1;
			if (end % 2 == 1)//目的地房間為奇數時加一
				end += 1;
			for (i = start; i <= end; ++i)//對走廊位置dp
				count[i] += 10;
		}
		printf("%d\n", *max_element(count, count + 400));//STL中尋找數列最大值函數
	}
	return 0;
}