codeforces 258B Little Elephant and Elections 数位DP+DFS
来源:互联网 发布:深度卷积网络怎么用 编辑:程序博客网 时间:2024/06/05 10:55
题意:在1-m中任选7个数,要使前六个数字中的“4”,"7"之和小于第七个的,问这样的分配方案的个数,答案要膜一下
做法:这道题目让我开始学了一下数位DP啊,今日继续。先用数位DP求出1-m中还有1个4,7,2个4、7等各种四七个数的数字的个数,然后,一开始没有法子...幸好渣的时候漂过大神的博客,他的做法中提到DFS,然后结合只有六个人的情况,果断DFS,这样暴力抉择出每一种情况,加之。
不好意思,写挫了...
#include<cstdio>#include<iostream>#define LL unsigned long long#define mod 1000000007//改程序是最容易出错const int LMT=12;const int MAN=7;using namespace std;LL cn[LMT][LMT],zn[LMT][LMT],num[LMT],have[LMT],ans;void init(void){ zn[0][0]=1; zn[1][0]=cn[1][0]=8;zn[1][1]=cn[1][1]=2; cn[1][0]=7; for(int i=2;i<LMT;i++) for(int j=0;j<=i;j++) { cn[i][j]+=cn[i-1][j]*8; zn[i][j]+=zn[i-1][j]*8; zn[i][j]%=mod; cn[i][j]%=mod; if(j>0) { zn[i][j]+=zn[i-1][j-1]*2; cn[i][j]+=cn[i-1][j-1]*2; zn[i][j]%=mod; cn[i][j]%=mod; } }}int leng(LL x){ int ret=0; do num[ret++]=x%10; while(x/=10); return ret;}void work(LL x){ int end,add=0,nad,len=leng(x); for(int i=len-1;i>0;i--) for(int j=0;j<LMT;j++) { have[j]+=cn[i][j]; have[j]%=mod; } for(int i=len-1;i>=0;i--) { if(i==len-1)end=1; else end=0; for(int j=num[i]-1;j>=end;j--) { nad=0; if(j==4||j==7)nad++; for(int t=0;t+nad+add<LMT;t++) { have[t+nad+add]+=zn[i][t]; have[t+nad+add]%=mod; } } if(num[i]==4||num[i]==7)add++; } have[add]++;}void dfs(int pos,LL result,int nhav){ if(nhav>=LMT-1)return; if(pos==MAN) { for(int i=nhav+1;i<LMT;i++) { ans+=(result*have[i])%mod; ans%=mod; } return; } for(int i=0;i<LMT;i++) if(have[i]) { have[i]--; dfs(pos+1,(result*(have[i]+1))%mod,nhav+i); have[i]++; }}int main(void){ LL m; init(); cin>>m; work(m); dfs(1,1,0); ans%=mod; cout<<ans<<endl; return 0;}
- codeforces 258B Little Elephant and Elections 数位DP+DFS
- Codeforces 258B. Little Elephant and Elections【数位DP,DFS】
- CodeForces 258B Little Elephant and Elections 数位DP
- codeforces 258B - Little Elephant and Elections 数位DP
- codeforces 258B Little Elephant and Elections 数位DP+排列组合
- [Codeforces 258B & 259 D]Little Elephant and Elections 数位dp+dfs
- 数位dp + dfs + 逆元求余 CF 258 B. Little Elephant and Elections
- Codeforces-258B Little Elephant and Elections
- Codeforces 258B Little Elephant and Elections
- Codeforces 258B - Little Elephant and Elections
- Codeforces Round #157 (Div. 1)B. Little Elephant and Elections 数位dp好
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections 数位dp
- CF 258B Little Elephant and Elections [dp+组合]
- CF 258B Little Elephant and Elections
- Codeforces Round #157 (Div. 1) B. Little Elephant and Elections
- codeforces 204A Little Elephant and Interval (数位dp)
- CodeForces 204A Little Elephant and Interval 数位DP
- Codeforces 204A Little Elephant and Interval(数位DP)
- 软件调试的一般思路
- asp.net开发中,web页面实现页面元素的多语言化(多国语化)
- 7K面试题,交通灯管理系统
- oracle expdb导出目录名无效
- 6.00 Introduction to Computer Science and Programming lec5: Objects in Python
- codeforces 258B Little Elephant and Elections 数位DP+DFS
- 随机数算法
- PHP扩展开发-07-函数调用
- INT 2DH中断
- hdu 2089 不要62 数位DP
- POJ 3252 Round Numbers 数位DP
- Windows下Red5安装与使用入门
- 天空之城
- Google Gson 加入到Android中, 打包编译混淆签名之后出现的错误