青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 195,  comments - 30,  trackbacks - 0

A supermarket has a set Prod of products on sale. It earns a profit px for each product x∈Prod sold by a deadline dx that is measured as an integral number of time units starting from the moment the sale begins. Each product takes precisely one unit of time for being sold. A selling schedule is an ordered subset of products Sell ≤ Prod such that the selling of each product x∈Sell, according to the ordering of Sell, completes before the deadline dx or just when dx expires. The profit of the selling schedule is Profit(Sell)=Σx∈Sellpx. An optimal selling schedule is a schedule with a maximum profit.
For example, consider the products Prod={a,b,c,d} with (pa,da)=(50,2), (pb,db)=(10,1), (pc,dc)=(20,2), and (pd,dd)=(30,1). The possible selling schedules are listed in table 1. For instance, the schedule Sell={d,a} shows that the selling of product d starts at time 0 and ends at time 1, while the selling of product a starts at time 1 and ends at time 2. Each of these products is sold by its deadline. Sell is the optimal schedule and its profit is 80.


Write a program that reads sets of products from an input text file and computes the profit of an optimal selling schedule for each set of products.

 

Input

A set of products starts with an integer 0 <= n <= 10000, which is the number of products in the set, and continues with n pairs pi di of integers, 1 <= pi <= 10000 and 1 <= di <= 10000, that designate the profit and the selling deadline of the i-th product. White spaces can occur freely in input. Input data terminate with an end of file and are guaranteed correct.

Output

For each set of products, the program prints on the standard output the profit of an optimal selling schedule for the set. Each result is printed from the beginning of a separate line.

Sample Input

4  50 2  10 1   20 2   30 1
7  20 1   2 1   10 3  100 2   8 2
5 20  50 10

 

Sample Output

80
185

 

Hint

The sample input contains two product sets. The first set encodes the products from table 1. The second set is for 7 products. The profit of an optimal schedule for these products is 185.


#include<iostream>
#include<cstdlib>
using namespace std;
#define MAX 10001
#define min(a,b) ((a)<(b) ? (a) : (b))
int father[MAX];
int p[MAX];
int result[MAX];
struct job{
     int value;
     int T;
  }JOB[MAX];
bool operator <(job job1,job job2)
 {
  if(job1.value>job2.value)
  return true;
  else
  return false;
 } 
 int find(int x)  //·µ»ØµÚ£Ø½ÚµãËùÊô¼¯ºÏµÄ¸ù½áµã
  {
int px=x;
while(p[px]>=0)
   px=p[px];
int tmp;
while(p[x]>=0)//ӦΪ³õֵΪ¸º
{
   tmp=p[x];
   p[x]=px;
   x=tmp;
}
return px;
}

   void UNION(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)
   return ;
int tmp=p[x]+p[y];
if(p[x]>p[y])
{
   p[y]=tmp;
   p[x]=y;
}
else
{
   p[x]=tmp;
   p[y]=x;
}
}
 
  int main()
  {
  freopen("s.txt","r",stdin);
  freopen("key.txt","w",stdout);
  int num,temp=0;
  while(cin>>num)
  {
  memset(result,0,num);
  int i,l,j,k=0;
  for( i=0;i<num;i++)
  {
   cin>>JOB[i].value>>JOB[i].T;
   father[i]=i;
   p[i]=-1;
  }
  sort(JOB,JOB+num);
  for(i=0;i<num;i++)
  {
   j=find(min(JOB[i].T,num-1));//
   if(father[j]!=0)
       {
     k++;
     result[k]=i;
        l=find(father[j]-1);
        UNION(l,j);
        father[j]=father[l];
    }
  }
  i=0;
  for(j=1;j<=k;j++)
  { 
   i+=JOB[result[j]].value;}
    cout<<i<<endl;
   }

  //system("PAUSE");
  return   0;
  }
對著課本寫得,自己都看不怎么懂。

posted on 2009-07-02 13:11 luis 閱讀(525) 評論(0)  編輯 收藏 引用 所屬分類: 貪心*二分
<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用鏈接

留言簿(3)

隨筆分類

隨筆檔案

文章分類

文章檔案

友情鏈接

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久综合国产精品| 性欧美18~19sex高清播放| 欧美精品二区| 久久婷婷麻豆| 亚洲图片欧美日产| 亚洲一区在线视频| 亚洲裸体在线观看| 亚洲高清123| 久久精品女人天堂| 欧美一区二区国产| 欧美一区二区视频在线观看| 亚洲欧美日韩一区二区在线| 9色精品在线| 亚洲区国产区| 99精品视频一区| 一区二区日韩精品| 一区二区欧美国产| 一区二区三区视频在线看| 一本色道久久88精品综合| 夜夜夜精品看看| 亚洲视频在线观看一区| 亚洲尤物在线视频观看| 亚洲欧美在线观看| 久久精品一区二区三区不卡| 久久亚洲风情| 欧美激情亚洲自拍| 亚洲精品视频啊美女在线直播| 午夜精品久久久久久久99水蜜桃| 一区在线影院| 亚洲区中文字幕| 亚洲午夜精品一区二区三区他趣| 午夜在线精品| 免费不卡视频| 亚洲日本电影| 欧美亚洲日本一区| 免费成人av| 国产精品久久久久免费a∨大胸| 国产精品国色综合久久| 国产原创一区二区| 99pao成人国产永久免费视频| 亚洲综合色在线| 蜜臀va亚洲va欧美va天堂 | 午夜精品国产更新| 午夜久久一区| 欧美成人一品| 亚洲私人影吧| 欧美成人久久| 国产日韩精品一区| 亚洲日本视频| 香蕉免费一区二区三区在线观看 | 欧美电影在线观看| 国产欧美激情| 欧美在线视频a| 日韩一级欧洲| 亚洲视频精选| 午夜在线视频观看日韩17c| 一区二区动漫| 亚洲免费一在线| 久久精品系列| 欧美韩国在线| 国产精品久久久久9999| 伊人狠狠色j香婷婷综合| 亚洲综合欧美| 日韩小视频在线观看专区| 午夜精品影院| 国产精品久久久久7777婷婷| 亚洲美女视频在线观看| 久热精品在线| 久久成人免费视频| 国产午夜精品久久久久久免费视 | 国产精品一区二区在线观看不卡| 夜夜夜久久久| 亚洲乱码国产乱码精品精| 免费成人黄色av| 怡红院精品视频| 久久亚洲风情| 久久精品人人做人人爽| 国产亚洲福利一区| 久久久久久久久岛国免费| 亚洲综合视频1区| 国产精品伦子伦免费视频| 一区二区三区精品在线| 亚洲精品影院| 欧美精品成人一区二区在线观看 | 尤物精品国产第一福利三区| 99精品热6080yy久久 | 欧美sm极限捆绑bd| 国产精品入口尤物| 欧美一区影院| 午夜精品理论片| 国产私拍一区| 久久日韩粉嫩一区二区三区| 狠狠综合久久av一区二区小说| 国产精品伦子伦免费视频| 亚洲线精品一区二区三区八戒| 免费成人高清| 欧美r片在线| 亚洲视频碰碰| 亚洲尤物视频网| 国内成+人亚洲| 欧美国产视频日韩| 欧美精品久久99| 亚洲免费视频成人| 西西裸体人体做爰大胆久久久| 国内精品美女av在线播放| 浪潮色综合久久天堂| 性8sex亚洲区入口| 亚洲高清av| 亚洲裸体在线观看| 国产亚洲精品久久久| 欧美好骚综合网| 亚洲尤物影院| 亚洲电影在线看| 一本一本a久久| 亚洲成色最大综合在线| 亚洲最新视频在线播放| 狠狠色香婷婷久久亚洲精品| 久久国产精品色婷婷| 久久久精品国产99久久精品芒果| 久久九九99| 亚洲视频网在线直播| 久久久久久久欧美精品| 韩日在线一区| 亚洲成人在线网| 欧美精品久久99久久在免费线| 先锋a资源在线看亚洲| 免费不卡亚洲欧美| 久久精品免费| 艳女tv在线观看国产一区| 亚洲美女精品成人在线视频| 国语精品中文字幕| 亚洲久久在线| 国产精品免费看| 欧美成va人片在线观看| 国产日韩精品在线播放| 亚洲精品一区二区三区四区高清| 狠狠色狠狠色综合系列| 在线综合+亚洲+欧美中文字幕| 亚洲国产99| 久久精品一区二区三区中文字幕 | 亚洲欧洲一区二区在线观看 | 亚洲欧美激情诱惑| 欧美成黄导航| 香港成人在线视频| 欧美日韩国产成人| 欧美jjzz| 免费在线看一区| 欧美在线免费观看| 欧美搞黄网站| 欧美成人伊人久久综合网| 99视频日韩| 欧美 日韩 国产一区二区在线视频| 欧美丝袜一区二区| 日韩视频在线免费| 国产欧美日韩激情| 亚洲一区三区在线观看| 99国产精品视频免费观看| 欧美伊人久久| 性色一区二区三区| 欧美激情一区二区三区成人| 久久丁香综合五月国产三级网站| 亚洲日本欧美天堂| 亚洲毛片网站| 日韩亚洲欧美一区| 亚洲欧美日韩区| 欧美国产日韩a欧美在线观看| 欧美顶级大胆免费视频| 亚洲国产va精品久久久不卡综合| 久久国产精彩视频| 巨胸喷奶水www久久久免费动漫| 国产综合精品| 鲁大师成人一区二区三区| 亚洲第一精品在线| 国产美女高潮久久白浆| 欧美伊人精品成人久久综合97 | 亚洲人成网站777色婷婷| 欧美成人精品三级在线观看| 亚洲午夜激情免费视频| 麻豆精品视频| 久久免费少妇高潮久久精品99| 很黄很黄激情成人| 久热精品视频在线观看一区| 99精品国产福利在线观看免费| 在线综合亚洲欧美在线视频| 国产日韩欧美另类| 久久亚洲精品欧美| 亚洲一区二区三区视频| 欧美专区一区二区三区| 一区视频在线播放| 欧美精品偷拍| 欧美在线日韩在线| 亚洲激情中文1区| 久久亚洲精品视频| 99国内精品久久| 亚洲国产成人一区| 国产精品久久波多野结衣| 欧美精品123区| 久久精品视频播放| 欧美一区二区三区日韩| 亚洲精品一区二区在线|