码迷,mamicode.com
首页 > 其他好文 > 详细

UESTC - 878 温泉旅店 二维费用背包问题

时间:2017-02-26 23:44:06      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:art   大小   lin   sed   type   ble   closed   assert   ons   

http://acm.uestc.edu.cn/#/problem/show/878

设dp[i][j][k]表示在前i个数中,第一个得到的异或值是j,第二个人得到的异或值是k的方案数有多少种。

因为异或后的大小不确定,所以不能压缩数组,但是也不大。。可以过。

技术分享
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;


#include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e2 + 20;
int a[maxn], n;
int ans;
int dp[20][500 + 20][500 + 20];
void work() {
    ans = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    dp[0][0][0] = true;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= 500; ++j) {
            for (int k = 0; k <= 500; ++k) {
                if (dp[i - 1][j][k]) {
                    dp[i][j][k] += dp[i - 1][j][k];
                    dp[i][j ^ a[i]][k] += dp[i - 1][j][k];
                    dp[i][j][k ^ a[i]] += dp[i - 1][j][k];
//                    if (j <= k) ans++;
                }
            }
        }
    }
    for (int i = 0; i <= 500; ++i) {
        for (int j = 0; j <= 500; ++j) {
            if (dp[n][i][j] && i <= j) {
                ans += dp[n][i][j];
            }
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    while (scanf("%d", &n) != EOF) work();
    return 0;
}
View Code

 

UESTC - 878 温泉旅店 二维费用背包问题

标签:art   大小   lin   sed   type   ble   closed   assert   ons   

原文地址:http://www.cnblogs.com/liuweimingcprogram/p/6457888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!