Number Cutting Game HDU - 2848(DFS)
两个对于一个数切割 k 次,然后切割以后把这些值加起来,然后继续切割 k 次,问谁先没有办法切割。
对于第一个人,先枚举每种切割的情况,然后拿去给第二个人切割,如果第二个人怎么样都没办法切割出来,那么就是第一个人赢。如果第二个人有办法切割,在枚举第二个人所有可以切割的情况,给第一个人切割,如果第一个人没法切割,那么第二个人赢,如果第一个人还有办法切割,就继续循环下去。
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lowbit(x) (x & (-x))
#define INOPEM freopen("in.txt", "r", stdin)
#define OUTOPEN freopen("out.txt", "w", stdout) typedef unsigned long long int ull;
typedef long long int ll;
const double pi = 4.0*atan(1.0);
const int inf = 0x3f3f3f3f;
const int maxn = 2e6+;
const int maxm = ;
const int mod = 1e9+;
using namespace std; ll n, m;
int T, tol;
ll a[]; ll dfs(ll nn, ll sum, ll cnt) {
if(cnt < m- && nn == ) return ;
if(cnt == m-) {
if(dfs(nn + sum, , )) return ;
return ;
}
for(int i=; a[i]<=nn; i++) {
if(dfs(nn/a[i], sum+nn%a[i], cnt+)) return ;
}
return ;
} int main() {
a[] = ;
for(int i=; i<=; i++) a[i] = a[i-]*;
while(~scanf("%lld%lld", &n, &m)) {
int ans = dfs(n, , );
printf("%d\n", ans);
}
return ;
}
Number Cutting Game HDU - 2848(DFS)的更多相关文章
- F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...
- Tempter of the Bone HDU - 1010(dfs)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Leetcode之深度优先搜索(DFS)专题-1020. 飞地的数量(Number of Enclaves)
Leetcode之深度优先搜索(DFS)专题-1020. 飞地的数量(Number of Enclaves) 深度优先搜索的解题详细介绍,点击 给出一个二维数组 A,每个单元格为 0(代表海)或 1( ...
- Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands)
Leetcode之深度优先搜索(DFS)专题-200. 岛屿数量(Number of Islands) 深度优先搜索的解题详细介绍,点击 给定一个由 '1'(陆地)和 '0'(水)组成的的二维网格,计 ...
- HDU 2553 N皇后问题(dfs)
N皇后问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 在 ...
- 深度优先搜索(DFS)和广度优先搜索(BFS)
深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...
- D - 淡黄的长裙 HDU - 4221(贪心)
D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
- LeetCode Subsets (DFS)
题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...
随机推荐
- 注入技术--LSP劫持注入
1.原理 简单来说,LSP就是一个dll程序. 应用程序通过winsock2进行网络通信时,会调用ws2_32.dll的导出函数,如connect,accept等. 而后端通过LSP实现这些函数的底层 ...
- tailf、tail -f、tail -F三者区别(转)
tail -f 等同于--follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止 tail -F 等同于--follow=name --retry,根 ...
- PhpStorm 配置链接远程虚拟机
安装好了 PhpStorm 之后,打开项目文件夹,接着点击工具栏 Tools: 2.接着点击 tools>Deployment: 3.点击Configuration 开始配置 4.填好箭头 ...
- docker 操作镜像的基本操作
以安装mysql为例 1.拉取镜像 docker pull mysql 错误的启动 [root@localhost ~]# docker run --name mysql01 -d mysql 42f ...
- RedHat 安装RabbitMQ
(以下均以root用户执行) 1.安装配置epel源rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noar ...
- bootstrap.css.map 404
删除bootstrap.css的最后一行即可: /*# sourceMappingURL=bootstrap.css.map */ English: from bootstrap-theme.css ...
- Netty派生缓冲区
参考https://blog.csdn.net/wangjinnan16/article/details/77972113 派生缓冲区 派生缓冲区,也就是创建一个已经存在的缓冲区的视图,可以调用dup ...
- 索引使用,分析初探。(explain分析执行计划,以及强制使用force index)
促使这次探索的初衷还是因为要对一个定时脚本性能进行优化. 脚本有两个指定状态分别是status, latest_process_status,和一个超期时间expire_time进行限制. 按照我以前 ...
- html5 autoplay不起作用 Uncaught (in promise) DOMException: play() failed because the user didn't interac
chrome://flags/#autoplay-policy
- Oracle 查询两个时间段内的所有日期列表
1.查询某时间段内日期列表 select level,to_char(to_date('2013-12-31','yyyy-mm-dd')+level-1,'yyyy-mm-dd') as date_ ...