数位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. mipi和dsi

    转自: http://blog.csdn.net/longxiaowu/article/details/24410021 一.MIPI MIPI(移动行业处理器接口)是Mobile Industry ...

  2. eclipse中的任务标记(TODO、FIXME、XXX)

    eclipse Task Tags: TODO -用来提醒该标识处的代码有待返回继续编写.更新或者添加.该标签通常在注释块的源文件顶部. FIXME -该标签用来提醒你代码中存在稍后某个时间需要修改的 ...

  3. 【JAVA Properties类概述】

    一.概述. 之前说过,该对象是和IO流相结合的技术,所以和IO流结合在一起来讲比较合适. public class Propertiesextends Hashtable<Object,Obje ...

  4. 攻城狮在路上(叁)Linux(十二)--- Linux的目录与路径

    一.相对路径与绝对路径: A.绝对路径:由根目录/开始写起的路径,例如 /usr/share/doc B.相对路径:不是由根目录/开始写起的路径. 二.目录的相关操作: 1.cd: 目录切换 cd ~ ...

  5. C程序设计语言习题解答

    1-6 #include <stdio.h> int main(void) { printf("getchar()!=EOF is:%d\n", getchar()!= ...

  6. JDK中的设计模式

    Creational(创建模式) Abstract factory: 创建一组有关联的对象实例.这个模式在JDK中也是相当的常见,还有很多的framework例如Spring.我们很容易找到这样的实例 ...

  7. RDS MySQL 全文检索相关问题的处理

    RDS MySQL 全文检索相关问题 1. RDS MySQL 对全文检索的支持 2. RDS MySQL 全文检索相关参数 3. RDS MySQL 全文检索中文支持 3.1 MyISAM 引擎表 ...

  8. Redis主从自动failover

    Redis主从架构持久化存在一个问题,即前次测试的结论,持久化需要配置在主实例上才能跨越实例保证数据不丢失,这样以来主实例在持久化数据到硬 盘的过程中,势必会造成磁盘的I/O等待,经过实际测试,这个持 ...

  9. Java可变参数讲解

    如果实现的多个方法,这些方法里面逻辑基本相同,唯一不同的是传递的参数的个数,可以使用可变参数可变参数的定义方法 数据类型...数组的名称,这个数组存储传递过来的参数,类似JavaScript注意点:  ...

  10. 多个$(document).ready()函数的执行顺序问题,(未解决)

    今天遇到了一个问题: jQuery获取不了动态添加的元素,我使用的是append添加的.寻求了帮助,得到解决方案: 在文件开头写上这样一段代码来获取,写在$(document).ready()里面. ...