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

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

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

      Codeforces Round #691 (Div. 1) B. Glass Half Spilled 背包DP

      B. Glass Half Spilled

      There are ?? glasses on the table numbered 1,…,??. The glass ?? can hold up to ???? units of water, and currently contains ???? units of water.

      You would like to choose ?? glasses and collect as much water in them as possible. To that effect you can pour water from one glass to another as many times as you like. However, because of the glasses' awkward shape (and totally unrelated to your natural clumsiness), each time you try to transfer any amount of water, half of the amount is spilled on the floor.

      Formally, suppose a glass ?? currently contains ???? units of water, and a glass ?? contains ???? units of water. Suppose you try to transfer ?? units from glass ?? to glass ?? (naturally, ?? can not exceed ????). Then, ??/2 units is spilled on the floor. After the transfer is done, the glass ?? will contain ??????? units, and the glass ?? will contain min(????,????+??/2) units (excess water that doesn't fit in the glass is also spilled).

      Each time you transfer water, you can arbitrarlly choose from which glass ?? to which glass ?? to pour, and also the amount ?? transferred can be any positive real number.

      For each ??=1,…,??, determine the largest possible total amount of water that can be collected in arbitrarily chosen ?? glasses after transferring water between glasses zero or more times.

      Input

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

      The following ?? lines describe the glasses. The ??-th of these lines contains two integers ???? and ???? (0≤????≤????≤100, ????>0) — capacity, and water amount currently contained for the glass ??, respectively.

      Output

      Print ?? real numbers — the largest amount of water that can be collected in 1,…,?? glasses respectively. Your answer will be accepted if each number is within 10?9 absolute or relative tolerance of the precise answer.

      Example

      input

      3
      6 5
      6 5
      10 2

      output

      7.0000000000 11.0000000000 12.0000000000

      Note

      In the sample case, you can act as follows:

      for ??=1, transfer water from the first two glasses to the third one, spilling (5+5)/2=5 units and securing 2+(5+5)/2=7 units;
      for ??=2, transfer water from the third glass to any of the first two, spilling 2/2=1 unit and securing 5+5+2/2=11 units;
      for ??=3, do nothing. All 5+5+2=12 units are secured.

      題意

      現在有n個水杯,每個水杯最多盛a[i]升水,現在每個水杯已經有b[i]升水

      你可以操作若干次,將A杯的水倒若干升到B杯,但是注意,你倒水的時候會灑掉一半。

      請問在操作若干次之后,讓你選擇k杯,最后最多能有多少升水。

      題解

      我們假設已經知道了最后選擇的K杯是哪幾杯。

      那么我們令最初的所有杯子的水的和為S1,最后選擇的K杯的水的和為S2,最后k杯水的容量為S3,那么:

      別的杯子最多給這k杯倒 (S1-S2)/2

      那么答案就是 min(S3, S2 + (S1-S2)/2) = min(S3,(S2+S1)/2)

      其中的未知數有S2,S3;現在的問題就是需要找到S2和S3的關系。

      DP[i][j][k],表示我們考慮前i個杯子,當前選了j個杯子,容量為k時,我最多能放多少水。

      經典老DP問題了:

      現在有一個背包,容積為k,我只能拿j個物品,每個物品只能拿一次,問你最大價值是多少。

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      
      const int maxn = 1e4+7;
      int dp[105][maxn]; // 前i個我選擇j個,容量為k的時候,最多能裝多少
      int a[105],b[105],n,suma,sumb;
      int main() {
      	cin>>n;
      	for (int i=1;i<=n;i++) {
      		cin>>a[i]>>b[i];
      		suma+=a[i];
      		sumb+=b[i];
      	}
      	for (int i=0;i<=n;i++) {
      		for (int j=0;j<=10000;j++) {
      			dp[i][j]=-1e9;
      		}
      	}
      	dp[0][0]=0;
      	for (int i=1;i<=n;i++) {
      		for (int j=n;j>=1;j--) {
      			for (int c=suma;c>=a[i];c--) {
      				dp[j][c]=max(dp[j][c],dp[j-1][c-a[i]]+b[i]);
      			}
      		}
      	}
      
      	for (int j=1;j<=n;j++) {
      		double ans = 0.0;
      		for (int c=0;c<=suma;c++) {
      			// dp[j][c]+(sumb-dp[j][c])/2
      			ans = max(ans, min(1.0*dp[j][c]+sumb, 2.0*c));
      		}
      		printf("%.10f ", ans/2.0);
      	}
      }
      
      posted @ 2020-12-23 10:57  qscqesze  閱讀(405)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 少妇办公室好紧好爽再浪一点| 久久精品国产亚洲不av麻豆| 国内视频偷拍久久伊人网| 116美女极品a级毛片| 色偷偷亚洲男人的天堂| 在线观看美女网站大全免费| 亚洲欧美日韩愉拍自拍| 在线看片免费人成视频久网 | 精品国产污污免费网站| 国产精品日本一区二区不卡视频| 女人被狂躁的高潮免费视频| 国内在线视频一区二区三区| 狠狠色噜噜狠狠狠狠av不卡| 久久精品国产亚洲av麻豆小说| 国产精品国产三级在线专区| 九九热在线免费视频精品| 无码精品人妻一区二区三区中 | 最新亚洲人成网站在线观看| 国产精品自产在线观看一| 亚洲国产精品日韩在线| 精品无码国产日韩制服丝袜| AV人摸人人人澡人人超碰| 亚洲成av人片无码天堂下载| 亚洲精品国产中文字幕| 欧美国产日产一区二区| 四虎网址| 无码国产精品一区二区VR老人 | 国产精品69人妻我爱绿帽子| 国产成人午夜福利高清在线观看| 国产精品国产精品一区精品| 丝袜美腿亚洲综合在线观看视频| 久久夜色撩人精品国产av| 美女高潮黄又色高清视频免费| 亚洲av免费成人精品区| 2020年最新国产精品正在播放| 久久不见久久见免费视频观看 | 婷婷丁香五月激情综合| 日韩va中文字幕无码电影| 亚洲日韩日本中文在线| 国产 麻豆 日韩 欧美 久久| 自拍亚洲一区欧美另类|