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 ...
随机推荐
- A Study of WebRTC Security
转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...
- PMP - 项目管理思维导图
- 装饰模式/decorator模式/结构型模式
装饰模式Decorator 定义 为对象动态的增加新的功能,实现要求装饰对象和被装饰对象实现同一接口或抽象类,装饰对象持有被装饰对象的实例. java实现要点 定义一个接口或抽象类,作为被装饰者的抽象 ...
- android之HttpURLConnection(转)
android之HttpURLConnection 1.HttpURLConnection连接URL1)创建一个URL对象 URL url = new URL(http://www.baidu.com ...
- Android三种基本的加载网络图片方式(转)
Android三种基本的加载网络图片方式,包括普通加载网络方式.用ImageLoader加载图片.用Volley加载图片. 1. [代码]普通加载网络方式 ? 1 2 3 4 5 6 7 8 9 10 ...
- 【项目经验】——JSON.parse() && JSON.stringify()
我们在做项目的时候,都知道序列化和反序列化,师哥说:"有正就有反,有来就有回!"的确,就是这样.然后我们在这里分享一下JSON.stringify() 和JSON.parse() ...
- LoadRunner下载文件脚本
LoadRunner下载文件脚本 在看普泽关于pezybase的测试报告的时候,发现里面有用到jmeter(http协议)并发测试下载文件,考虑到后面可能需要在公司pezybase的并发下载,把之前 ...
- Android的ADB配置环境和adb指令使用
adb的全称为Android Debug Bridge,就是起到调试桥的作用,作为一名开发者倒是常用到这个工具.借助adb工具,我们可以管理设备或手机模拟器的状态.还可以进行很多手机操作,如安装软件. ...
- poj1745 dp
题目链接:http://poj.org/problem?id=1745 类似的题目之前写过一个差不多的(链接:http://www.cnblogs.com/a-clown/p/5982611.html ...
- 1、Delphi 打开目录和txt文件模块
//1.打开目录和打开txt文件 procedure TMainForm.bbtnOpenLoClick(Sender: TObject); var sLogName: string; begin s ...