HDU2848 Number Cutting Game

题解:

记忆化搜索

如何把数分割为k个部分并且求和。以及如何编程这个博弈过程。。挺考查代码能力的

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200100;
const int mod=1e9+7;
const int INF=1e9;

LL Base[22];

void makebase()
{
    Base[1]=10;
    for(int i=2;i<22;i++) Base[i]=Base[i-1]*10;
}

bool dfs(LL,int);

bool test(LL n,int d,int k,LL cur)
{
    if(d==k) return !dfs(cur+n,k);
    for(int i=1;i<22;i++)
    {
        LL a=n%Base[i];
        LL b=n/Base[i];
        if(!b) break;
        if(test(b,d+1,k,cur+a)) return true;
    }
    return false;
}

bool dfs(LL n,int k)
{
    if(n<Base[k-1]) return false;
    return test(n,1,k,0);
}

int main()
{
    LL n;
    int k;
    makebase();
    while(~scanf("%lld%d",&n,&k))
    {
        int flag=dfs(n,k);
        printf("%d\n",flag);
    }
    return 0;
}
时间: 2025-01-19 23:01:02

HDU2848 Number Cutting Game的相关文章

codechef Cutting Recipes题解

Cutting Recipes The chef has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredie

UVA 10003 - Cutting Sticks

#include<iostream> #include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<algorithm> using namespace std; in

UVA 10003 Cutting Sticks(区间dp)

Description  Cutting Sticks  You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of work requires that they onl

【HDU 5909】 Tree Cutting (树形依赖型DP+点分治)

Tree Cutting Problem Description Byteasar has a tree T with n vertices conveniently labeled with 1,2,...,n. Each vertex of the tree has an integer value vi. The value of a non-empty tree T is equal to v1⊕v2⊕...⊕vn, where ⊕ denotes bitwise-xor. Now fo

IKEYCUTTER Condor XC-007 key cutting machine Tech Support

Q: When install update tool, the system warns can not find FTD2XX.dll file?A: You have to install the software driver first. Q: How can I access into "Factory Mode"?A: Power off the XC-007 key cutting machine Press both the right up button and l

Pizza Cutting

Pizza Cutting When someone calls Ivan lazy, he claims that it is his intelligence that helps him to be so. If hisintelligence allows him to do something at less physical effort, why should he exert more? He alsoclaims that he always uses his brain an

poj 2378 Tree Cutting (树形dp)

Tree Cutting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3910   Accepted: 2347 Description After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible

POJ 2378 Tree Cutting(树的重心)

题目链接:http://poj.org/problem?id=2378 题目: Description After Farmer John realized that Bessie had installed a "tree-shaped" network among his N (1 <= N <= 10,000) barns at an incredible cost, he sued Bessie to mitigate his losses. Bessie, fee

Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array ss consisting of nn integers. You have to find any ar