CF255--D--優先隊列

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   資料   

這題 的確是個好題~   當時 只覺得應該用貪心做...

後來 人家給我證明了下 不應該是用貪心  局部最優解 與 全域最優解之間的關係不是嚴格成立的~

     touch   me

慢慢 靜心下來 總是有解決的方法的=-=

 

 1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 using namespace std; 5  6 typedef long long LL; 7 const int size = 1000010; 8 const LL inf = 1e18; 9 LL a[1010] , b[1010];10 LL row[size] , col[size];11 priority_queue<LL>rowQu,colQu;12 13 int main()14 {15     cin.sync_with_stdio(false);16     LL n , m , k , p , i , j , num , ans , temp;17     while( cin >> n >> m >> k >> p )18     {19         for( i = 1 ; i<=n ; i++ )20         {21             for( j = 1 ; j<=m ; j++ )22             {23                 cin >> num;24                 a[i] += num;25                 b[j] += num;26             }27             rowQu.push(a[i]); 28         }29         for( j = 1 ; j<=m ; j++ )30         {31             colQu.push(b[j]);32         }33         ans = -inf;34         for( i = 1 ; i<=k ; i++ )35         {36             temp = rowQu.top();37             rowQu.pop();38             row[i] = row[i-1] + temp;39             rowQu.push(temp-m*p);40             41             temp =  colQu.top();42             colQu.pop();43             col[i] = col[i-1] + temp;44             colQu.push(temp-n*p);45         }46         for( i = 0 ; i<=k ; i++ )47         {48             temp = row[i] + col[k-i];49             temp -= (i)*(k-i)*p;50             if( temp>ans )51                 ans = temp;52         }53         cout << ans << endl;54     }55     return 0;    56 }
View Code

這裡 因為資料很大 用到64位 那麼 ans就要設定得足夠小... 一開始 我就用自己慣用的0x3f3f3f3f  會wa的~

以後 做好每場cf  一般感覺我以後cf要貼出來的 都是後來看別人的解題報告才學會的~

//今天 睡到下午2點半才醒 好累.....  世界盃 終於結束了

 

today:

  這是一個流行離開的世界 但是我們都不擅長告別~

  你終於活得如同一般人類學行為規範 去掉了表情 隱藏了情緒 不帶一絲人氣 成了 橡皮人~

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.