标签:黑子 203 ABC int auto st vt White include
E - White Pawn
DP
设 \(st[y]\) 表示 \((2*n,y)\) 是否能到达
初始化 \(st[n]=true\)
-
若 \((x,y)\) 是白子,则 \(st[y]\) 的值为 \(y\) 这一列的上一个黑子的值
-
若 \((x,y)\) 是黑子,则 \(st[y]=st[y-1]\;or\;st[y+1]\)
所以将 黑子按 \(x\) 从小到大排序,不断更新 \(st\) 即可
但若两个黑子在同一行且相邻,它们的只应该与这一行之前最近的 \(y-1,y+1\) 的黑子的值有关
但按上述转移则求完一个黑子后,\(st[y]\) 被更新了,那下一个黑子用到的 \(st\) 值已经被覆盖了
所以可以对于每一行的 \(y\), 先把他们的答案放到 \(tmp\) 中,这一行都更新完了再给 \(st\) 赋值
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int n, m;
map<int, vector<int> > mp;
map<int, bool> st;
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
int x, y;
cin >> x >> y;
mp[x].push_back(y);
}
for (auto [i, vt] : mp)
sort(vt.begin(), vt.end());
st[n] = true;
for (auto [i, vt] : mp)
{
map<int, bool> tmp;
for (auto y : vt)
tmp[y] = st[y-1] | st[y+1];
for (auto [y, s] : tmp)
st[y] = tmp[y];
}
int ans = 0;
for (auto [y, s] : st)
ans += s;
cout << ans << endl;
return 0;
}
标签:黑子,203,ABC,int,auto,st,vt,White,include 来源: https://www.cnblogs.com/hzy717zsy/p/16301055.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。