Codeforces - 440C DFS

Posted The Azure Arbitrator

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces - 440C DFS相关的知识,希望对你有一定的参考价值。

搜索苦手,注意正负

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i = j; i <=k; i++)
using namespace std;
const int maxn = 55;
typedef long long ll;
ll one[maxn];
ll n;
ll dfs(ll n,ll i){
    ll k = n/one[i];
    ll j = n%one[i];
    if(j==0) return k*i;
    return k*i+min(i+dfs(one[i]-j,i-1),dfs(j,i-1));
}
int main(){
    one[0]=0;
    rep(i,1,16) one[i]=10*one[i-1]+1;
    while(cin>>n) cout<<dfs(n,16)<<endl;
    return 0;
} 

以上是关于Codeforces - 440C DFS的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #290 (Div. 2) B (dfs)

CodeForces 731C Socks (DFS或并查集)

CodeForces 884A.B.C Book Reading(水) | Japanese Crosswords Strike Back(水) | Bertown Subway(DFS)(示例代码

CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)

CodeForces 375D Tree and Queries 莫队||DFS序

Codeforces 982 C. Cut 'em all!(dfs)