[杂技] 关于双折线的实现

老写错就看板子!
记某条折线是 \(y = x + a\) , 翻折的时候就 \(x -= a, y += a\) !
一开始的答案是 \(C(x + y, y)\) , 每次翻折一次以后算答案!
换个起点开始!
第一次是减法!

void rev1(int &x, int &y) {
	swap(x, y); x --; y ++;
}

void rev2(int &x, int &y) {
	swap(x, y); x += m; y -= m;
}

signed main() {
	freopen("tree.in", "r", stdin);
	freopen("tree.out", "w", stdout);
	init();
	n = read(); m = read(); n = n * 2 - 2; n /= 2; m --;
	//if(n < m) { cout << 0 << endl; return 0; }
	int ans = 0;
	int x = n, y = n;
	ans = C(x + y, y);
	int d = 0;
	while(x >= 0 && y >= 0) {
		d ^= 1;
		if(d) rev1(x, y), ans = (ans + P - C(x + y, y)) % P;
		else rev2(x, y), ans = (ans + C(x + y, y)) % P;
	}
	d = 0;
	x = n, y = n;
	while(x >= 0 && y >= 0) {//cerr << x << ' ' << y << endl;
		if(d) rev1(x, y), ans = (ans + C(x + y, y)) % P;
		else rev2(x, y), ans = (ans + P - C(x + y, y)) % P;
		d ^= 1;
	}
		
	cout << ans << endl;
	return 0;	
}
posted @ 2022-01-07 14:32  HN-wrp  阅读(10)  评论(0编辑  收藏  举报