Codeforces Round #243 (Div. 1)——Sereja and Two Sequences

时间:2014-04-30 22:13:40   收藏:0   阅读:261

题目链接

const int MAXN = 100001;

int ipta[MAXN], iptb[MAXN];
int dp[2][310];
vector<int> vt[MAXN];
int main()
{
	//    freopen("in.txt", "r", stdin);
	int a, b, all, c, cnt;
	while (~RIV(a, b, all, c))
	{
		int cur = 0;
		CLR(dp, INF);
		REP(i, MAXN) vt[i].clear();
		cnt = (all + c - 1) / c;
		FE(i, 1, a) RI(ipta[i]);
		FE(i, 1, b)
		{
			RI(iptb[i]);
			vt[iptb[i]].push_back(i);
		}
		int ans = 0;
		FE(i, 1, a)
		{
			dp[cur][0] = 0;
			cur ^= 1;
			CLR(dp[cur], INF);
			FE(j, 1, cnt)
			{
				int pre = dp[cur ^ 1][j - 1];
				int p = upper_bound(all(vt[ipta[i]]), pre) - vt[ipta[i]].begin();
				if (p == vt[ipta[i]].size()) p = INF;
				else p = vt[ipta[i]][p];
				dp[cur][j] = min(dp[cur ^ 1][j], p);
				if (dp[cur ^ 1][j] > p && p + i + j * c <= all)
					ans = max(ans, j);
			}
		}
		WI(ans);
	}
	return 0;
}



评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!