题意:给一串数字,第一个数是Num的话,要使后面的数字组成Num个数,而且为不降的,将这Num个数分配到9个素因子上作为指数,问能组成多少个不同的数

解法:dfs一遍,看后面的数字能组成Num个不降数字的方法种数,及该种方法的不同数字的个数,然后这些方法加起来。具体见代码吧。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;
#define N 30017 int C,Num;
string S;
int c[] = {,,,,,,,,,};
int cnt[];
ll a[];
int tot,len;
ll Res; ll fac(int n)
{
ll res = 1LL;
for(int i=n;i>=;i--)
res *= i;
return res;
} void calc()
{
ll res = fac(Num)*c[Num];
for(int i=;i<tot;i++)
res /= fac(cnt[i]);
Res += res;
} void check(int u,int v,int num)
{
if(num == Num && u == v)
{
calc();
return;
}
ll ans = ;
if(num == Num)
return;
if(S[u] == '')
return;
for(int i=u;i<v;i++)
{
ans += 10LL*ans + S[i]-'';
if(num == || ans >= a[tot-])
{
if(ans == a[tot-]) //重复
{
cnt[tot-]++;
check(i+,len,num+);
cnt[tot-]--;
}
else //非重复,新建
{
cnt[tot]++;
a[tot++] = ans;
check(i+,len,num+);
cnt[tot-]--;
tot--;
}
}
}
} int main()
{
int t,i;
scanf("%d",&t);
while(t--)
{
cin>>S;
Num = S[]-'';
len = S.length();
tot = ;
Res = ;
check(,len,);
printf("%lld\n",Res);
}
return ;
}

UVA 12377 Number Coding --DFS的更多相关文章

  1. UVa 12377 - Number Coding

    题目:一个数能够用一种素数元素的个数表示的形式,43560=23×32×51×112表示成41223: 第一个数是素因子的种类,第二个是每一个素因子的个数递增排列.给你一个这样的形式的串, 问原来的数 ...

  2. UVA 1558 - Number Game(博弈dp)

    UVA 1558 - Number Game 题目链接 题意:20之内的数字,每次能够选一个数字,然后它的倍数,还有其它已选数的倍数组合的数都不能再选,谁先不能选数谁就输了,问赢的方法 思路:利用dp ...

  3. UVA - 11853 Paintball(dfs)

    UVA - 11853 思路:dfs,从最上面超过上边界的圆开始搜索,看能不能搜到最下面超过下边界的圆. 代码: #include<bits/stdc++.h> using namespa ...

  4. UVA.548 Tree(二叉树 DFS)

    UVA.548 Tree(二叉树 DFS) 题意分析 给出一棵树的中序遍历和后序遍历,从所有叶子节点中找到一个使得其到根节点的权值最小.若有多个,输出叶子节点本身权值小的那个节点. 先递归建树,然后D ...

  5. uva 11885 - Number of Battlefields(矩阵高速幂)

    题目连接:uva 11885 - Number of Battlefields 题目大意:给出周长p,问多少种形状的周长为p的,而且该图形的最小包围矩阵的周长也是p,不包含矩形. 解题思路:矩阵高速幂 ...

  6. 【UVa】11882 Biggest Number(dfs+剪枝)

    题目 题目     分析 典型搜索,考虑剪枝. 统计一下联通分量. 1.本位置能够达到所有的点的数量加上本已有的点,还没有之前的结果长,直接返回. 2.当本位置能够达到所有的点的数量加上本已有的点与之 ...

  7. UVA - 1103Ancient Messages(dfs)

    UVA - 1103Ancient Messages In order to understand early civilizations, archaeologists often study te ...

  8. UVa 572 油田(DFS求连通块)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

随机推荐

  1. CSS基础选择器温故-1

    1.基本选择器语法 2.浏览器兼容性:浏览器对基本选择器都是一路绿灯通行,可以放心使用. 3.通配选择器:选择所有元素,也可以选择某个元素下的所有元素 (1)选择所有元素: *{margin: 0;p ...

  2. DAX 2009 for Retail's P job does not work after restoring AX database from another environment.

    This time, it's P job.  We already re-configured profiles, distribution locations, distribution grou ...

  3. Sharepoint 2013 开启App和配置App

    在任何站点中,点Add App,然后点Sharepoint Store,如果没有Enable apps,打开app store的时候出出现错误: Sorry, apps are turned off. ...

  4. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q94-Q96)

    Question 94You need to create a custom application that provides users with the ability to create a ...

  5. 讲解Canvas中的一些重要方法

    Canvas所提供的各种方法根据功能来看大致可以分为几类: 第一是以drawXXX为主的绘制方法: 第二是以clipXXX为主的裁剪方法: 第三是以scale.skew.translate和rotat ...

  6. NSMutable sort排序

    Compare method Either you implement a compare-method for your object: - (NSComparisonResult)compare: ...

  7. git学习笔记1

    很早以前就听说了git,今天就开始使用git,并做简单记录 在Linux上安装Git 首先,你可以试着输入git,看看系统有没有安装Git: $ git The program 'git' is cu ...

  8. IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。

    (1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/ (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDelegate中一般情况下有三 ...

  9. 将tomcat源码导入eclipse

    前言: 写完了socket小应用的原始版本,中间还有好多预想的功能没有实现,在写的过程中也发现了很多问题.因为前面有粗略的看过tomcat实现原理解析,知道tomcat其实也是纯java写的web服务 ...

  10. IOS之资源收集--很好的github网址

    1.Nick Jensen 2.关于直播的