Codeforces Round #157 (Div. 2) D. Little Elephant and Elections(数位DP+枚举)
数位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+枚举)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #157 (Div. 2)
A. Little Elephant and Chess 模拟. B. Little Elephant and Magic Square 枚举左上角,计算其余两个位置的值,在\(3\times 3\) ...
- 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 ...
- 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 ...
- 字符串(后缀自动机):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 ...
- 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 ...
随机推荐
- gnuplot安装问题(set terminal "unknown")
今天在系统同上要装个gnuplot,原来用的都是拷好的虚拟机.这也是第一次装.本来以为分分钟的事,却不料遇到不少麻烦.记录一下,供大家参考 一,快速开始安装 ubuntu下那自然是: sudo apt ...
- [Spring Batch] 图解Spring Batch原理
找到一副以前学习的图,稻清楚的描述了Spring Batch运行原理:
- 免费电子书:Azure Web Apps开发者入门
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:之前介绍过微软正在逐步出版一个名为Azure Essential的入门系列教程,最近刚 ...
- linux的<pthread.h>
转自:http://blog.sina.com.cn/s/blog_66cc44d00100in5b.html Linux系统下的多线程遵循POSIX线程接口,称为pthread.编写Linux下的多 ...
- iOS和Android的app界面设计规范(转)
记录一下iOS和Andoird的界面设计规范,方便进行标准的产品设计,并与设计师顺畅沟通 iOS篇 界面尺寸 设备 分辨率 状态栏高度 导航栏高度 标签栏高度 iPhone6 plus 1242×22 ...
- java发展史与java的语言特性
概述: Java 体系比较庞杂,功能繁多,这也导致很多人在自学 Java 的时候总是感觉无法建立 全面的知识体系, 无法从整体上把握Java 的原因. 在这里我们先简单了解一下Java 的版本. 具体 ...
- LoadRunner关联之学习笔记
去银行办业务,进银行的门,大堂经理给你一张业务号,拿着这张业务号,去柜台办理业务.--录制下来 第二天又去银行,还是拿着这张业务号,去柜台办理业务,柜员就不理你了,因为这张业务号是昨天的.--回放过程 ...
- Markdown语言.md文件
转自:http://www.kuqin.com/shuoit/20141125/343459.html 之前一直在使用github,也在上面分享了不少的项目和Demo,每次创建新项目的时候,使用的都是 ...
- Intel CPU MMX SSE SSE2/3/4指令集手册下载URL
在线查看的网址: https://software.intel.com/sites/landingpage/IntrinsicsGuide/ Intel® 64 and IA-32 Architect ...
- python 定义类方法
定义类方法 和属性类似,方法也分实例方法和类方法. 在class中定义的全部是实例方法,实例方法第一个参数 self 是实例本身. 要在class中定义类方法,需要这么写: class Person( ...