UESTC - 878 温泉旅店 二维费用背包问题
2017-02-26 23:11
441 查看
http://acm.uestc.edu.cn/#/problem/show/878
设dp[i][j][k]表示在前i个数中,第一个得到的异或值是j,第二个人得到的异或值是k的方案数有多少种。
因为异或后的大小不确定,所以不能压缩数组,但是也不大。。可以过。
View Code
设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 [i][j] && i <= j) { ans += dp [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
相关文章推荐
- TOJ 3596. Watch The Movie【基础的二维费用背包问题】
- hdu 3496 Watch The Movie(二维费用的背包问题)
- 二维费用的背包问题
- 杭电2159-二维费用的背包问题
- 背包问题总结第六讲——二维费用的背包问题
- 杭电 2159 FATE(二维费用背包问题)
- 第五讲 二维费用的背包问题 HD FATE(二维完全背包)
- UESTC_温泉旅店 CDOJ 878
- HDU 2159 FATE 动态规划二维费用的背包问题
- P05: 二维费用的背包问题
- HDU 2159 二维费用背包问题
- HDU 2159 FATE 【二维费用的完全背包问题】
- HDU-2159 FATE(二维费用背包问题)
- P05: 二维费用的背包问题
- hdu 4501 小明系列故事——买年货(二维费用背包问题)
- P05:二维费用的背包问题
- HDU 2159 二维费用背包问题
- 二维费用的背包问题
- 【背包九讲】P05: 二维费用的背包问题
- 【转】背包九讲——多重背包问题 ,二维费用背包