【HDOJ】3419 The Three Groups
记忆化搜索。
/* 3419 */
#include <cstdio>
#include <cstring>
#include <cstdlib> #define MAXN 10 int ans;
int n[];
int x[];
bool visit[MAXN];
int cnt[MAXN][MAXN][MAXN]; void dfs(int d, int i, int v) {
if (i == ) {
if (x[]*x[] == x[])
++ans;
return ;
}
if (d < n[i]) {
for (int j=; j<MAXN; ++j) {
if (!visit[j]) {
visit[j] = true;
dfs(d+, i, v*+j);
visit[j] = false;
}
}
} else {
x[i] = v;
dfs(, i+, );
}
} int main() {
int a, b, c;
int i, j, k; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif memset(cnt, -, sizeof(cnt));
while (scanf("%d %d %d", &a, &b, &c)!=EOF && (a||b||c)) {
if (a+b < c) {
puts("");
} else if (a>c || b>c){
puts("");
} else if (a+b-c>) {
puts("");
} else if (cnt[a][b][c] >= ) {
printf("%d\n", cnt[a][b][c]);
} else {
memset(visit, false, sizeof(visit));
n[] = a;
n[] = b;
n[] = c;
ans = ;
dfs(, , );
cnt[a][b][c] = ans;
printf("%d\n", ans);
}
} return ;
}
【HDOJ】3419 The Three Groups的更多相关文章
- 【HDOJ】1669 Jamie's Contact Groups
二分+二分图多重匹配. /* 1669 */ #include <iostream> #include <string> #include <map> #inclu ...
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
随机推荐
- 在LINUX中跟踪函数调用----http://stackoverflow.com/
http://stackoverflow.com/questions/311840/tool-to-trace-local-function-calls-in-linux I am looking f ...
- iOS-UIControls介绍
iOS-UIControls类介绍 UIControl的继承关系 UIControl是 UIKit中UISwitch(开关).UIButton(按钮).UISegmentedControl(分段控件) ...
- Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法
1.最容易想到的估计就是利用String类的toCharArray(),再倒序输出数组的方法了: package himi.hebao05; public class TestDemo02 { pub ...
- iOS UIKit:Auto Layout
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- Customizing the Test Runner
There are several situations where you want to customize Robolectric's test runner to perform some o ...
- Driving the Activity Lifecycle
Before Robolectric 2.2, most tests created Activities by calling constructors directly, (new MyActiv ...
- rabbitmq 消息持久化
rabbitmq 消息持久化 2016-02-18 11:19 224人阅读 评论(0) 收藏 举报 分类: 综合(15) 版权声明:本文为博主原创文章,未经博主允许不得转载. 二: 任务分发 & ...
- Weex 样式
1.盒型 width height padding padding-left padding-right padding-top padding-bottom margin margin-left m ...
- openwrt advanced configuration
openwrt高级配置(汗 照着标题就翻译过来了) openwrt Kamikaze 8.09的一般配置文件都在目录 /etc/config 下面,可以使用脚本来调用参数和设置参数. 比如 sbin/ ...
- 层模型--固定定位(position:fixed)
fixed:表示固定定位,与absolute定位类型类似,但它的相对移动的坐标是视图(屏幕内的网页窗口)本身. 由于视图本身是固定的,它不会随浏览器窗口的滚动条滚动而变化,除非你在屏幕中移动浏览器窗口 ...