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

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>
            欧美伊人久久久久久久久影院| 亚洲国产三级| 国产欧美一区二区精品秋霞影院 | 免费观看日韩| 欧美日韩在线免费| 国产精品mm| 91久久精品一区| 久久久久久夜| 亚洲午夜三级在线| 欧美精品一区二| 在线免费不卡视频| 久久99伊人| 亚洲一级二级| 精品51国产黑色丝袜高跟鞋| 亚洲欧美中日韩| 亚洲毛片在线看| 免费亚洲网站| 亚洲欧美日韩国产一区二区三区| 91久久久亚洲精品| 久久婷婷综合激情| 午夜精品久久久久久99热软件| 欧美日韩一本到| 麻豆亚洲精品| 久久只有精品| 亚洲电影在线看| 欧美不卡在线视频| 麻豆成人在线播放| 亚洲电影免费观看高清| 亚洲美女一区| 国产精品区一区| 久久se精品一区精品二区| 另类专区欧美制服同性| 国产精品99久久久久久久女警 | 欧美r片在线| 午夜精品久久久久久99热| 久久综合给合久久狠狠色 | 亚洲欧美国产日韩天堂区| 久久久久久久网| 亚洲国产精选| 性欧美长视频| 在线观看欧美日韩国产| 亚洲国产mv| 欧美日韩精品综合| 午夜综合激情| 久久久久国产精品一区二区| 亚洲色图在线视频| 欧美成人一区二区| 一区二区欧美国产| 亚洲免费视频观看| 亚洲电影在线免费观看| 亚洲欧美中文在线视频| 亚洲一级黄色片| 欧美一级免费视频| 亚洲国内高清视频| 久久久亚洲一区| 久久乐国产精品| 国产日韩欧美综合一区| 欧美www在线| 激情丁香综合| 久久国产欧美| 夜夜嗨av一区二区三区免费区| 亚洲一区二区三区涩| 黄色国产精品一区二区三区| 亚洲精品乱码久久久久久按摩观| 国产精品入口尤物| 国产精品99久久久久久www| 国产综合视频| 一区二区国产日产| 亚洲第一中文字幕| 噜噜噜躁狠狠躁狠狠精品视频| 久久综合精品国产一区二区三区| 国产亚洲一区精品| 这里只有视频精品| 欧美一区二区精品| 欧美精品尤物在线| 麻豆91精品| 亚洲国产欧美日韩另类综合| 欧美成人免费大片| 亚洲精品免费在线观看| 亚洲综合色视频| 欧美大片一区二区| 99热这里只有成人精品国产| 精品动漫一区二区| 蜜桃精品一区二区三区 | 久久精品人人做人人爽电影蜜月| 欧美久久在线| 亚洲午夜小视频| 久久精品91久久香蕉加勒比| 激情欧美一区二区三区| 欧美精品1区2区| 亚洲一区二区免费在线| 久久免费视频在线| 亚洲精品午夜精品| 麻豆91精品91久久久的内涵| 亚洲黄色免费| 亚洲日本久久| 国产精品婷婷| 老司机午夜免费精品视频| 亚洲精品视频中文字幕| 久久九九99视频| 国产亚洲一二三区| 欧美承认网站| 欧美在线关看| 日韩亚洲成人av在线| 久久资源在线| 午夜精品成人在线视频| 亚洲国产精品嫩草影院| 国产精品手机视频| 欧美激情第五页| 亚洲另类在线一区| 久久最新视频| 午夜宅男久久久| 一本大道久久a久久综合婷婷 | 欧美国产日韩一区二区在线观看 | 蜜桃av噜噜一区| 亚洲欧美日韩爽爽影院| 亚洲国产美女精品久久久久∴| 欧美一级电影久久| 亚洲一区在线播放| 亚洲精品日韩一| 在线不卡欧美| 国产欧美日本| 国产精品日韩欧美大师| 欧美日本一道本在线视频| 麻豆精品一区二区av白丝在线| 午夜国产欧美理论在线播放 | 亚洲成人在线视频播放| 亚洲国产精品成人综合| 国产日本欧美一区二区| 欧美日韩免费观看一区| 欧美成人精品1314www| 巨乳诱惑日韩免费av| 久久爱www| 午夜精品久久久久久久蜜桃app | 国产精品乱看| 久久嫩草精品久久久久| 亚洲欧洲综合| 亚洲国产综合在线| 亚洲电影免费| 亚洲国产成人在线| 亚洲福利精品| 亚洲国语精品自产拍在线观看| 嫩草伊人久久精品少妇av杨幂| 久久精品一区二区国产| 久久激情视频| 鲁大师成人一区二区三区| 久久人91精品久久久久久不卡 | 亚洲丝袜av一区| 一区二区欧美日韩| 亚洲男人第一网站| 欧美在线免费视频| 久久精品国产亚洲一区二区三区| 欧美一级大片在线观看| 久久国产精品99国产| 久久影院午夜论| 欧美顶级少妇做爰| 欧美在线观看视频| 久久精品一区二区三区中文字幕| 久久久久www| 欧美国产日韩在线观看| 久久久成人网| 欧美成人在线网站| 亚洲美女精品久久| 亚洲欧美日韩综合一区| 久久精品国产一区二区三区免费看| 一本一本久久| 午夜精品视频在线| 久久麻豆一区二区| 欧美日韩在线视频观看| 国产女同一区二区| 亚洲人成网站色ww在线| 亚洲视频在线观看| 久久精品国产亚洲一区二区| 欧美激情一区| 亚洲一区二区成人| 久色婷婷小香蕉久久| 欧美日韩少妇| 樱桃成人精品视频在线播放| 日韩视频免费在线观看| 亚洲日本中文字幕区| 亚洲女性喷水在线观看一区| 久久一区二区三区国产精品| 亚洲精品国产精品国自产观看| 欧美亚洲在线观看| 欧美日韩国产综合新一区| 国产综合久久久久久鬼色| 日韩一区二区免费看| 夜夜嗨av一区二区三区网页| 久久久久久久综合狠狠综合| 亚洲理论在线观看| 老司机亚洲精品| 欧美影视一区| 亚洲精品一区二区三区四区高清| 欧美在线视频在线播放完整版免费观看 | 亚洲欧美另类综合偷拍| 欧美成在线观看| 西西人体一区二区| 欧美视频在线一区| 洋洋av久久久久久久一区| 美女脱光内衣内裤视频久久网站|