<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #687 (Div. 1, based on Technocup 2021 Elimination Round 2) D - Cakes for Clones DP

      D. Cakes for Clones

      You live on a number line. You are initially (at time moment ??=0) located at point ??=0. There are ?? events of the following type: at time ???? a small cake appears at coordinate ????. To collect this cake, you have to be at this coordinate at this point, otherwise the cake spoils immediately. No two cakes appear at the same time and no two cakes appear at the same coordinate.

      You can move with the speed of 1 length unit per one time unit. Also, at any moment you can create a clone of yourself at the same point where you are located. The clone can't move, but it will collect the cakes appearing at this position for you. The clone disappears when you create another clone. If the new clone is created at time moment ??, the old clone can collect the cakes that appear before or at the time moment ??, and the new clone can collect the cakes that appear at or after time moment ??.

      Can you collect all the cakes (by yourself or with the help of clones)?

      Input

      The first line contains a single integer ?? (1≤??≤5000) — the number of cakes.

      Each of the next ?? lines contains two integers ???? and ???? (1≤????≤109, ?109≤????≤109) — the time and coordinate of a cake's appearance.

      All times are distinct and are given in increasing order, all the coordinates are distinct.

      Output

      Print "YES" if you can collect all cakes, otherwise print "NO".

      Examples

      input

      3

      2 2

      5 5

      6 1

      output

      YES

      input

      3

      1 0

      5 5

      6 2

      output

      YES

      input

      3

      2 1

      5 5

      6 0

      output

      NO

      Note

      In the first example you should start moving towards 5 right away, leaving a clone at position 1 at time moment 1, and collecting the cake at position 2 at time moment 2. At time moment 5 you are at the position 5 and collect a cake there, your clone collects the last cake at time moment 6.

      In the second example you have to leave a clone at position 0 and start moving towards position 5. At time moment 1 the clone collects a cake. At time moment 2 you should create a new clone at the current position 2, it will collect the last cake in future. You will collect the second cake at position 5.

      In the third example there is no way to collect all cakes.

      翻譯

      有一條線,你站在0這個點。

      現在有n個事件,表示有一個蛋糕將會在t[i]秒出現在x[i]的位置,你每秒可以移動1,然后你的任務是吃掉所有的蛋糕。

      你現在有個功能,就是你可以在你的位置生成一個克隆,這個克隆不能移動,可以一直呆在原地吃蛋糕,但是同時只能存在一個蛋糕。

      問你是否存在一個方案吃掉所有的蛋糕。

      題解

      考慮最最暴力的dp, dp[i][j]表示吃掉1~i,克隆體在第j個位置的最小花費是多少。

      3方的dp

      for (int i=1;i<=n;i++) {
      	for (int j=i+1;j<=n;j++) {
      		for (int k=i-1;k<=n;k++) {
      			if (j!=k) {
      				dp[i][j]=min(dp[i][j], cost + dp[i-1][k]);
      			}
      		}
      		// 轉移一下 j==k 的情況,就可以到處放克隆體
      	}
      }
      

      n3肯定是會TLE的,優化一下發現有些狀態是不需要的,我們不需要存儲克隆體在j的最小花費。

      我們定義minTime[i],表示我們在吃完了[1,i-1]所有蛋糕,且我在x[i]的最小花費是多少

      dp[i][j]表示吃完了[1,i]的所有蛋糕,人在x[i],分身放在x[j]是否可行。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 5005;
      int n;
      long long t[maxn],x[maxn];
      long long dp[maxn][maxn],minTime[maxn];
      long long dis(long long x,long long y) {
      	return abs(x-y);
      }
      int main() {
      	cin>>n;
      	for (int i=1;i<=n;i++) {
      		cin>>t[i]>>x[i];
      		minTime[i] = 1e17;
      	}
      	minTime[0]=0;
      	dp[0][0]=1;
      	for (int i=1;i<=n;i++) {
      		if (x[i] == 0) {
      			dp[0][i]=1;
      		}
      	}
      
      	for (int i=1;i<=n;i++) {
      		// 從x[i-1]點出發, 不靠分身
      		if (minTime[i-1] <= t[i-1]) {
      			minTime[i] = min(minTime[i], max(minTime[i-1] + dis(x[i], x[i-1]), t[i-1]));
      			if (minTime[i] <= t[i]) {
      				dp[i][i]=1;
      			}
      		}
      
      		// 站在i點,分身放在j點,又回來
      		for (int j=i;j<=n;j++) {
      			if (minTime[i]+2*dis(x[i],x[j])<=t[i]) { // 過去又回來
      				dp[i][j]=1;
      			}
      		}
      
      		// 從i-1點出發,人在i,分身仍然留在j
      		for (int j=i+1;j<=n;j++) {
      			if (dp[i-1][j] && t[i-1] + dis(x[i], x[i-1]) <= t[i]) {
      				dp[i][j] = 1;
      			}
      		}
      
      		// 從i-1 -> j放下分身,i-1 -> i吃
      		for (int j=i+1;j<=n;j++) {
      			if (minTime[i-1]<=t[i-1] && max(t[i-1],minTime[i-1]+dis(x[j],x[i-1]))+dis(x[j],x[i])<=t[i]) {
      				dp[i][j]=1;
      			}
      		}
      
      		// 2 dp[i-1][i]是合法的 -> dp[i+1][i] / minTime[i+1]
      		if (dp[i-1][i] && i+1 <= n) {
      			minTime[i+1] = min(minTime[i+1], max(t[i-1] + dis(x[i+1],x[i-1]), t[i]));
      			if (minTime[i+1] <= t[i+1]) {
      				dp[i+1][i+1]=1;
      			}
      			// 先去j,等待分身i吃完,放下分身,再去i+1
      			for (int j=i+1;j<=n;j++) {
      				if (max(t[i-1]+dis(x[j],x[i-1]),t[i])+dis(x[j],x[i+1]) <= t[i+1]) {
      					dp[i+1][j] = 1;
      				}
      			}
      		}
      	}
      	if (dp[n][n] == 1 || dp[n-1][n] == 1) {
      		cout<<"YES"<<endl;
      	} else {
      		cout<<"NO"<<endl;
      	}
      }
      
      posted @ 2020-12-14 21:07  qscqesze  閱讀(227)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产一区二三区日韩精品| 熟女人妻aⅴ一区二区三区电影| 丰满少妇被猛烈进出69影院| 亚洲免费观看在线视频| 亚洲色一色噜一噜噜噜| 五月婷婷久久草| 中文字幕无码视频手机免费看| 成人国产精品日本在线观看| 亚洲国产大胸一区二区三区| 无码精品人妻一区二区三李一桐 | 欧美牲交a欧美牲交aⅴ免费真| 大地资源中文在线观看西瓜| 国产女高清在线看免费观看| 日本高清中文字幕免费一区二区| 久久精品国产99国产精品严洲| 亚洲中文字幕一区二区| 宜都市| 国产自产对白一区| 亚洲欧美在线观看品| 国产麻豆精品一区一区三区| 人妻无码av中文系列久| 国产精品一区二区国产馆| 日韩免费视频一一二区| mm1313亚洲国产精品| 久久精品国产亚洲av麻豆长发| 色偷偷www.8888在线观看| 国产无遮挡性视频免费看| 午夜福利啪啪片| 国产精品无码免费播放| 久久一日本综合色鬼综合色| 国产精品亚洲专区无码导航 | 国产精品亚洲二区亚瑟| 亚洲精品日韩在线丰满| 少妇人妻真实偷人精品| 精品午夜福利在线视在亚洲| 国产精品极品美女自在线观看免费| 亚洲首页一区任你躁xxxxx| 无码人妻黑人中文字幕| 亚洲人成网站色7799| 国产片av在线观看国语| 男女真人国产牲交a做片野外|