数位DP部分,不是很难。DP[i][j]前i位j个幸运数的个数。枚举写的有点搓。。。

 #include <cstdio>
#include <cstring>
using namespace std;
#define LL __int64
#define MOD 1000000007
int dp[][];
int p[],num;
int o[];
int dfs(int pos,int pre,int bound)
{
int ans,i,end;
ans = ;
if(pos == -)
return pre == ;
if(!bound&&dp[pos][pre] != -)
return dp[pos][pre];
end = bound ? p[pos]:;
for(i = ;i <= end;i ++)
{
if(i == ||i == )
ans += dfs(pos-,pre-,bound&&i == end);
else
ans += dfs(pos-,pre,bound&&i == end);
}
if(!bound)
dp[pos][pre] = ans;
return ans;
}
void CL(int m)
{
num = ;
while(m)
{
p[num++] = m%;
m /= ;
}
}
int main()
{
int i,m;
int a1,a2,a3,a4,a5,a6,sum;
LL ta1,ta2,ta3,ta4,ta5,ta6;
LL ans,t1,t2;
memset(dp,-,sizeof(dp));
scanf("%d",&m);
CL(m);
for(i = ;i <= ;i ++)
{
o[i] = dfs(num-,i,);
}
o[] --;
ans = ;
for(a1 = ;a1 <= ;a1 ++)
{
ta1 = o[a1];
o[a1] -- ;
for(a2 = ;a2 <= &&o[a1] >= ;a2 ++)
{
ta2 = o[a2];
o[a2] -- ;
for(a3 = ;a3 <= &&o[a2] >= ;a3 ++)
{
ta3 = o[a3];
o[a3] -- ;
for(a4 = ;a4 <= &&o[a3] >= ;a4 ++)
{
ta4 = o[a4];
o[a4] -- ;
for(a5 = ;a5 <= &&o[a4] >= ;a5 ++)
{
ta5 = o[a5];
o[a5] -- ;
for(a6 = ;a6 <= &&o[a5] >= ;a6 ++)
{
ta6 = o[a6];
o[a6] -- ;
sum = a1 + a2 + a3 + a4 + a5 + a6;
if(sum <= &&o[a6] >= )
{
t1 = ta1;
t1 = t1*ta2%MOD;
t1 = t1*ta3%MOD;
t1 = t1*ta4%MOD;
t1 = t1*ta5%MOD;
t1 = t1*ta6%MOD;
t2 = ;
for(i = sum+;i <= ;i ++)
t2 += o[i];
ans = (ans + t1*t2)%MOD;
}
o[a6] ++ ;
}
o[a5] ++ ;
}
o[a4] ++ ;
}
o[a3] ++ ;
}
o[a2] ++;
}
o[a1] ++ ;
}
printf("%I64d\n",ans);
return ;
}

Codeforces Round #157 (Div. 2) D. Little Elephant and Elections(数位DP+枚举)的更多相关文章

  1. Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp+搜索

    题目链接: http://codeforces.com/problemset/problem/258/B B. Little Elephant and Elections time limit per ...

  2. Codeforces Round #235 (Div. 2) D. Roman and Numbers (数位dp、状态压缩)

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  3. Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp

    F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...

  4. Codeforces Round #460 (Div. 2) B Perfect Number(二分+数位dp)

    题目传送门 B. Perfect Number time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces Round #157 (Div. 2)

    A. Little Elephant and Chess 模拟. B. Little Elephant and Magic Square 枚举左上角,计算其余两个位置的值,在\(3\times 3\) ...

  6. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  7. Codeforces Round #136 (Div. 1)C. Little Elephant and Shifts multiset

    C. Little Elephant and Shifts Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/pro ...

  8. 字符串(后缀自动机):Codeforces Round #129 (Div. 1) E.Little Elephant and Strings

    E. Little Elephant and Strings time limit per test 3 seconds memory limit per test 256 megabytes inp ...

  9. Codeforces Round #136 (Div. 1) B. Little Elephant and Array

    B. Little Elephant and Array time limit per test 4 seconds memory limit per test 256 megabytes input ...

随机推荐

  1. 解析PHP处理换行符的问题 \r\n

    一首先说说 \r 与\n的区别回车”(Carriage Return)和“换行”(Line Feed)这两个概念的来历和区别.在计算机还没有出现之前,有一种叫做电传打字机(Teletype Model ...

  2. 【JAVA网络流之TCP与UDP 】

    一.ServerSocket java.lang.Object |-java.net.ServerSocket 有子类SSLServerSocket. 此类实现服务器套接字.服务器套接字等待请求通过网 ...

  3. 使用zookeeper实现分布式锁

    简介: 核心是解决资源竞争的问题 分布式系统中经常需要协调多进程或者多台机器之间的同步问题,得益于zookeeper,实现了一个分布式的共享锁,方便在多台服务器之间竞争资源时,来协调各系统之间的协作和 ...

  4. [荐]使用Js操作注册表

    使用Js操作注册表 要操作注册表需要通过ActiveX控件调用WScript.shell对象,通过该对象的一些方法来操作. WshShell对象:可以在本地运行程序.操纵注册表内容.创建快捷方式或访问 ...

  5. WebStorm中将Project分享到GitHub时报“Error Running Git”错误的解决办法

    错误信息 Cannot run program "git.exe":CreateProcess error=2,系统找不到指定的文件. 解决办法 从错误信息就可以知道,WebSto ...

  6. C语言基本点初探

    1,对于int a=10++;此语句错误,为什么呢,对于i++来说,i是一个变量,是把i加1然后赋值给i,然而10不是一个变量所以无法执行加加的语法; 2,运算符的优先级: 赋值运算符<逻辑运算 ...

  7. css把超出的部分显示为省略号的方法兼容火狐

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  8. 学习linux内核时常碰到的汇编指令(1)

     转载:http://blog.sina.com.cn/s/blog_4be6adec01007xvg.html 80X86 汇编指令符号大全 +.-.*./∶算术运算符. &∶宏处理操作符. ...

  9. form表单验证和事件

    1.表单验证<form></form> (1).非空验证(去空格) (2).对比验证(跟一个值对比) (3).范围验证(根据一个范围进行判断) (4).固定格式验证:电话号码, ...

  10. 指针数组 vs 数组指针

        指针数组,故名思义,就是指针的数组,数组的元素是指针:     数组指针,同样,就是直想数组的指针.     简单举例说明:     int *p[2]; 首先声明了一个数组,数组的元素是in ...