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

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>
            91久久综合亚洲鲁鲁五月天| 一个色综合av| 欧美日韩国语| 国产精品激情| 国产一区二区三区视频在线观看| 国产亚洲电影| 在线欧美不卡| 一区二区激情视频| 亚洲在线观看| 久久综合亚洲社区| 亚洲激情午夜| 亚洲欧美视频在线观看视频| 午夜在线不卡| 欧美成人中文字幕在线| 欧美午夜激情在线| 国产一区二区视频在线观看| 在线观看亚洲视频| 一区二区三区四区国产精品| 久久精品国产免费观看| 欧美国产日韩视频| 亚洲资源av| 美女日韩欧美| 国产精品一区二区在线观看| 亚洲国产91| 欧美一级片久久久久久久| 欧美黑人在线观看| 亚洲欧美日韩一区| 欧美日韩国产不卡在线看| 狠狠综合久久av一区二区小说| 在线亚洲精品| 欧美成人免费网| 午夜久久一区| 99精品视频免费在线观看| 亚洲精品美女在线| 亚洲一区免费视频| 欧美wwwwww| 亚洲欧美日韩国产精品| 欧美日韩国产大片| 亚洲国产精品日韩| 久久激情久久| 亚洲欧美另类在线| 国产精品xxxxx| 99re8这里有精品热视频免费 | 欧美91大片| 国产欧美精品在线播放| 一区二区三区高清在线| 欧美成人中文字幕在线| 性xx色xx综合久久久xx| 国产精品国产三级国产专播品爱网 | 亚洲国产欧美在线人成| 久久只精品国产| 亚洲自拍电影| 国产伦精品一区二区三区免费迷 | 另类天堂视频在线观看| 欧美在线欧美在线| 好看不卡的中文字幕| 久久精品国产免费观看| 午夜欧美大片免费观看| 国产九九精品视频| 久久精品免费电影| 欧美一区久久| 狠狠入ady亚洲精品经典电影| 久久久国产成人精品| 欧美综合国产精品久久丁香| 国产综合色产| 蜜臀av性久久久久蜜臀aⅴ四虎| 久久国产精品高清| 激情小说亚洲一区| 欧美第一黄色网| 欧美承认网站| 一区二区三区高清在线| 亚洲一区国产视频| 国产日韩欧美综合在线| 久久久亚洲影院你懂的| 久久永久免费| 亚洲精品欧美精品| 在线一区视频| 国产亚洲制服色| 男女视频一区二区| 欧美日韩国产欧| 欧美一区三区三区高中清蜜桃| 午夜精品一区二区三区在线| 精品999久久久| 久久精品成人一区二区三区 | 亚洲精品久久视频| 99re这里只有精品6| 国产欧美视频一区二区三区| 久久一综合视频| 欧美激情亚洲自拍| 欧美一区不卡| 欧美jjzz| 久久精品一二三区| 欧美福利电影网| 欧美在线视频导航| 欧美精品粉嫩高潮一区二区| 久久国产精品久久久久久久久久| 美国成人直播| 欧美一级片久久久久久久| 久久精品一二三区| 亚洲一区精品视频| 久久亚洲精选| 欧美一区二区三区精品| 美女诱惑一区| 久久不射中文字幕| 欧美日韩高清区| 欧美大片91| 黄色成人在线网站| 亚洲午夜av电影| 一二三四社区欧美黄| 久久看片网站| 久久久久久亚洲精品杨幂换脸 | 亚洲精品日韩欧美| 在线观看一区视频| 欧美亚洲综合久久| 亚洲欧美精品中文字幕在线| 欧美肥婆在线| 欧美岛国在线观看| 一区二区视频免费在线观看| 亚洲自拍偷拍一区| 亚洲亚洲精品在线观看 | 伊人久久大香线| 亚洲欧美日韩精品在线| 亚洲午夜精品福利| 欧美日韩激情小视频| 亚洲国产日韩在线一区模特| 伊人久久大香线| 久久女同互慰一区二区三区| 久久精品欧洲| 国产亚洲美州欧州综合国| 亚洲一区二区三区视频播放| 亚洲午夜性刺激影院| 欧美日韩国产系列| 亚洲毛片视频| 亚洲婷婷国产精品电影人久久 | 经典三级久久| 久久久国产午夜精品| 久久综合色88| 亚洲国产成人不卡| 久久一区精品| 亚洲国产经典视频| 日韩视频―中文字幕| 欧美精品一区二区三区蜜桃| 亚洲电影成人| 最新69国产成人精品视频免费| 亚洲三级电影全部在线观看高清| 亚洲精品影视在线观看| 91久久久在线| 欧美不卡视频| 亚洲精华国产欧美| 99精品欧美一区| 欧美日韩一区二区在线视频 | 欧美一区二区三区婷婷月色| 国产精品免费区二区三区观看| 亚洲午夜久久久| 欧美在线播放高清精品| 激情综合色丁香一区二区| 蜜臀av性久久久久蜜臀aⅴ| 91久久久久久国产精品| 午夜视频一区| 在线不卡免费欧美| 欧美激情一区二区三区在线视频观看 | 最新亚洲激情| 国产精品每日更新在线播放网址| 欧美一级欧美一级在线播放| 久久综合网络一区二区| 99视频国产精品免费观看| 国产精品久久久久aaaa樱花| 欧美一区二区三区在线| 亚洲第一中文字幕| 性色av一区二区三区在线观看 | 欧美在线一级va免费观看| 牛牛影视久久网| 亚洲视频一区二区在线观看| 国产一区二区三区日韩欧美| 欧美精品日日鲁夜夜添| 新狼窝色av性久久久久久| 亚洲国产午夜| 久久久久久999| 亚洲午夜久久久久久久久电影院| 国色天香一区二区| 欧美日韩成人在线| 久久久久久久久岛国免费| av成人老司机| 亚洲第一伊人| 久久免费观看视频| 亚洲欧美日韩另类| 日韩图片一区| 影音先锋欧美精品| 国产日韩欧美日韩| 欧美香蕉视频| 欧美激情一区二区三级高清视频 | 亚洲精品三级| 国产主播在线一区| 国产精品毛片高清在线完整版| 欧美国产日本高清在线| 久久久久久久综合| 欧美一区午夜视频在线观看| 一区二区三区四区五区精品视频| 亚洲福利视频一区二区| 男人天堂欧美日韩|