標籤: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:
這是一個流行離開的世界 但是我們都不擅長告別~
你終於活得如同一般人類學行為規範 去掉了表情 隱藏了情緒 不帶一絲人氣 成了 橡皮人~