狀態壓縮 hdu #10

來源:互聯網
上載者:User

標籤:ane   a+b   maximum   mem   lld   center   res   分享圖片   range   

You are playing CSGO.
There are n Main Weapons and m Secondary Weapons in CSGO. You can only choose one Main Weapon and one Secondary Weapon. For each weapon, it has a composite score S.
The higher the composite score of the weapon is, the better for you.
Also each weapon has K performance evaluations x[1], x[2], …, x[K].(range, firing rate, recoil, weight…)
So you shold consider the cooperation of your weapons, you want two weapons that have big difference in each performance, for example, AWP + CZ75 is a good choose, and so do AK47 + Desert Eagle.
All in all, you will evaluate your weapons by this formula.(MW for Main Weapon and SW for Secondary Weapon)

Now you have to choose your best Main Weapon & Secondary Weapon and output the maximum evaluation.
InputMultiple query.
On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.
for each group, the first line have three positive integers n, m, K.
then, the next n line will describe n Main Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
then, the next m line will describe m Secondary Weapons, K+1 integers each line S, x[1], x[2], …, x[K]
There is a blank line before each groups of data.
T<=100, n<=100000, m<=100000, K<=5, 0<=S<=1e9, |x[i]|<=1e9, sum of (n+m)<=300000
OutputYour output should include T lines, for each line, output the maximum evaluation for the corresponding datum.Sample Input
22 2 10 2330 6660 1230 4562 2 1100 0 1000 100 1000 100100 0
Sample Output
5432000
題意 : 有 n 種主武器, m 種副武器, 同時每種武器都有 k 個權值,詢問上面所給的目標式子中的最大收益
思路分析 : 考慮一下絕對值的性質, a-b 的絕對值等於 a-b 或者 -a+b , 並且題目所給的 k <= 5, 顯然這裡我們可以二進位去枚舉,記錄最大值即可
程式碼範例:
#define ll long longconst ll maxn = 1e5+5;ll n, m, k;ll a[maxn][10], b[maxn][10];ll sa[50], sb[50];void init() {    ll f = 1;    for(ll i = 1; i <= k; i++) f *= 2;    memset(sa, 0x8f, sizeof(sa)); memset(sb, 0x8f, sizeof(sb));    //printf("++ %lld \n", sa[0]);    for(ll i = 1; i <= n; i++){        for(ll state = 0; state < f; state++){            ll sum = 0;            for(ll j = 0; j < k; j++){                if (state & (1<<j)) sum += a[i][j+1];                else sum -= a[i][j+1];            }            sa[state] = max(sa[state], sum+a[i][0]);        }    }        for(ll i = 1; i <= m; i++){        for(ll state = 0; state < f; state++){            ll sum = 0;            for(ll j = 0; j < k; j++){                if (state & (1<<j)) sum += b[i][j+1];                else sum -= b[i][j+1];            }            sb[state] = max(sb[state], sum+b[i][0]);        }    }}void solve() {    ll num = 1<<k;    ll ans = 0x8f;    for(ll i = 0; i < num; i++){        ll pp = num-1-i;                ans = max(ans, sa[i]+sb[pp]);     }    printf("%lld\n", ans);}int main() {    //freopen("in.txt", "r", stdin);    //freopen("out.txt", "w", stdout);    ll t;        cin >> t;    while(t--){        scanf("%lld%lld%lld", &n, &m, &k);        for(ll i = 1; i <= n; i++){            for(ll j = 0; j <= k; j++){                scanf("%lld", &a[i][j]);            }        }        for(ll i = 1; i <= m; i++){            for(ll j = 0; j <= k; j++){                scanf("%lld", &b[i][j]);            }        }        init();        solve();    }        return 0;}

 

狀態壓縮 hdu #10

聯繫我們

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