Bzoj2034 2009國家集訓隊試題 最大收益 貪心+各種最佳化+二分圖

來源:互聯網
上載者:User

標籤:http   os   io   for   art   ar   問題   div   

這個題真的是太神了。。。

從一開始枚舉到最後n方的轉化,各種最佳化基本都用到了極致。。。。


FQW的題解寫了好多,個人感覺我全然沒有在這裡廢話的必要了

直接看這裡


各種方法真的是應有盡有


大概說下


首先能夠想到一個KM演算法求二分圖最大代權匹配的問題對吧

左邊是任務右邊是時間

可是這個是三次方啊


那我們就按價值排序,這樣就不用代權匹配了可是還是三方


可是左邊在右邊的連線是單調的。。。

所以就能夠貪心推斷了。。。

#include<iostream>#include<cstring>#include<cstdio>#include<algorithm>#define MAX 5010#define rep(i,j,k) for(int i = j; i <= k; i++)using namespace std;int n, Link[MAX];long long ans = 0;int b[MAX];struct wbysr{int Begin, end, value;} a[MAX];bool cmp (wbysr a1, wbysr a2){return a1.Begin < a2.Begin || (a1.Begin == a2.Begin && a1.end < a2.end);}bool cmp2 (wbysr a1, wbysr a2){return a1.value > a2.value;}bool find (int now, int x){if (b[x] > a[now].end)return 0;if (!Link[x]){Link[x] = now;return 1;}int j = Link[x];if (a[now].end > a[j].end)return find (now,x + 1);else{if (find(j, x + 1)){Link[x] = now;return 1;}}return 0;}int main(){scanf ("%d", &n);rep (i, 1, n)scanf ("%d%d%d", &a[i].Begin, &a[i].end, &a[i].value);sort (a + 1, a + 1 + n, cmp);int now = 0;rep (i, 1, n){now = max (now + 1, a[i].Begin);b[i] = now;}sort (a + 1, a + 1 + n, cmp2);b[n+1] = 0x7fffffff / 3;rep (i, 1, n){int j;for (j = 1; j <= n; j++)if (b[j] >= a[i].Begin && b[j] <= a[i].end)break;if (find(i, j))ans += a[i].value;}cout << ans << endl;return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.