多维完全背包 USACO 3.3.2 Shopping Offers
2012-07-19 19:22
399 查看
典型多维完全背包
/*
PROG:fence
LANG:C++
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 501;
int d[MAXN], tot, ans[10000], n, up, down = ~0U>>1;
int a[MAXN][MAXN];
void dfs(int x)
{
for (int i = 1;i <= up;++i)
{
if (a[x][i])
{
--a[x][i], --a[i][x];
dfs(i);
}
}
ans[++tot] = x;
}
int main()
{
freopen("fence.in", "r", stdin);
freopen("fence.out", "w", stdout);
scanf("%d", &n);
int x, y;
for (int i = 1;i <= n;++i)
{
scanf("%d%d", &x, &y);
up = max(x, up), up = max(y, up);
++d[x], ++d[y];
++a[x][y], ++a[y][x];
}
for (int i = 1;i <= up;++i)
{
if (d[i]) down = min(i, down);
if (d[i] & 1) { down = i; break; }
}
dfs(down);
for (int i = tot;i > 0;--i)
printf("%d\n", ans[i]);
}
/*
PROG:fence
LANG:C++
*/
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 501;
int d[MAXN], tot, ans[10000], n, up, down = ~0U>>1;
int a[MAXN][MAXN];
void dfs(int x)
{
for (int i = 1;i <= up;++i)
{
if (a[x][i])
{
--a[x][i], --a[i][x];
dfs(i);
}
}
ans[++tot] = x;
}
int main()
{
freopen("fence.in", "r", stdin);
freopen("fence.out", "w", stdout);
scanf("%d", &n);
int x, y;
for (int i = 1;i <= n;++i)
{
scanf("%d%d", &x, &y);
up = max(x, up), up = max(y, up);
++d[x], ++d[y];
++a[x][y], ++a[y][x];
}
for (int i = 1;i <= up;++i)
{
if (d[i]) down = min(i, down);
if (d[i] & 1) { down = i; break; }
}
dfs(down);
for (int i = tot;i > 0;--i)
printf("%d\n", ans[i]);
}
相关文章推荐
- 【BZOJ1708】[Usaco2007 Oct]Money奶牛的硬币【完全背包】
- usaco Shopping Offers(多重完全背包)
- C++&Pascal——【USACO 3.3.2】——Shopping Offers
- bzoj1708 [Usaco2007 Oct]Money奶牛的硬币(完全背包)
- ACM--steps--3.3.2--Piggy-Bank(完全背包)
- [usaco]4.1.3 Fence Rails 多维背包问题,dfsid
- Shopping Offers USACO 3.3 (dp完全背包)
- USACO-Section3.1 Score Inflation【完全背包】
- bzoj 1655: [Usaco2006 Jan] Dollar Dayz 奶牛商店【高精度+完全背包】
- USACO 3.1 Score Inflation (完全背包) P2722 总分 Score Inflation
- bzoj1578[Usaco2009 Feb]Stock Market 股票市场 完全背包
- USACO Score Inflation,完全背包问题
- [USACO 2.3.4]货币系统【DP完全背包的简单应用】CSUST 1081
- USACO / Shopping Offers (多维背包)
- USACO Score Inflation,完全背包问题
- USACO3.3.2--Shopping Offers
- [USACO 2.3.4]货币系统【DP完全背包的简单应用】CSUST 1081
- USACO-Section3.3 Home on the Range【完全背包】
- USACO 3.1 Score Inflation (完全背包)
- USACO--3.1Score Inflation+完全背包问题