题意:给一串数字,第一个数是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. (旧)子数涵数·DW——图文混排页面

    一.首先,打开Dreamweaver,新建一个的HTML项目. 二.在设计区里,写一些文字,随便写一点(也可以在代码区中的<body>和</body>之间写). 三.插入一张图 ...

  2. ahjesus 创建msdn一样的帮助文档

    转载自http://www.cnblogs.com/DotNetNuke/archive/2009/04/23/1441899.html 使用SandCastle创建.Net帮助文档 Sandcast ...

  3. [Android] 环境配置之基础开发环境(SDK/Android Studio)(转)

    [Android] 环境配置之基础开发环境(SDK/Android Studio)   博客: blog.csdn.net/qiujuer 网站: www.qiujuer.net 开源库: Geniu ...

  4. zend framework2学习(一)初步入门

    声明:本人菜鸟一枚,由于项目中需要用到zf2框架进行开发,在此记载学习使用过程中的点点滴滴.才疏学浅,请多指教............. ------------------------------- ...

  5. [js开源组件开发]图片懒加载lazyload

    图片懒加载lazyload 前端对请求的一种优化方式,为什么叫懒加载,无从查起,反正我当初一直认为它是滚动加载的一种类型.它主要是以图片或背景在可视区域内时才显示真正的图片,减少src带来的负荷.所以 ...

  6. jquery 监控文本框键盘事件(回车事件),附常用keycode值。

    $(function(){ $(".search").keydown(function(event) { ) { //执行操作 } }) ); 完整的 key press 过程分为 ...

  7. ABAP中使用浏览器打开网页

    在SAP ABAP中可以在Screen中嵌入Html control打开网页,也可以通过调用本地的IE浏览器打开. 1.在Screen中嵌入Html control的例子,在系统中有,se38:SAP ...

  8. Oracle Spatial中SDO_Geometry详细说明[转]

    在ArcGIS中通过SDE存储空间数据到Oracle中有多种存储方式,分别有:二进制Long Raw .ESRI的ST_Geometry以及基于Oracle Spatial的SDO_Geometry等 ...

  9. ubuntu解决libstdc++.so.6: cannot open shared object file: No such file or directory:问题

    解决libstdc++.so.6: cannot open shared object file: No such file or directory:原因在于,在13.10 版本中,ia32_lib ...

  10. Android 5中不同效果的Toast

    一.运行的结果 二.主要的代码 package com.otn.android.toast; import java.util.Timer; import java.util.TimerTask; i ...