http://poj.org/problem?id=1769
2.Idea
DP + Segtree
3.Source
int n, m;
int s[MAX_M], t[MAX_M];
int dp[MAX_N + 1];
void solve()
{
rmq_init(n);
fill(dp, dp + n + 1, INF);
dp[1] = 0;
update(1, 0);
for (int i = 0; i < m; i++) {
int v = min(dp[t[i]], query(s[i], t[i] + 1) + 1);
dp[t[i]] = v;
update(t[i], v);
}
printf("%d\n", dp[n]);
}
No comments:
Post a Comment