DP 水题
来源:互联网 发布:湖南电信网络测速 编辑:程序博客网 时间:2024/05/21 06:49
如果一个自然数N的K进制表示中任意的相邻的两位都不是相邻的数字,那么我们就说这个数是K好数。求L位K进制数中K好数的数目。例如K = 4,L = 2的时候,所有K好数为11、13、20、22、30、31、33 共7个。由于这个数目很大,请你输出它对1000000007取模后的值。
有点数位DP的味道,这个要记得不相邻,但是自己跟自己可以。还有就是枚举的是往前插
dp[i][j] 长i,j打头的个数。又有点递推味道。
#include<algorithm>#include<iostream>#include<iterator>#include<cstdlib>#include<cstring>#include<cstdio>#include<map>#define mem(a) memset(a,0,sizeof(a))#define inf (1<<30)#define mod 1000000007using namespace std;typedef long long ll;const int maxn=10+100;ll dp[20][20];int main(){ int k,l; scanf("%d%d",&k,&l); for(int i=0;i<k;i++) dp[1][i]=1; for(int i=2;i<=l;i++) for(int j=1;j<k;j++) { dp[i][j]=dp[i-1][j]; for(int m=0;m<j-1;m++) dp[i][j]+=dp[i-1][m]; for(int m=j+2;m<k;m++) dp[i][j]+=dp[i-1][m]; dp[i][j]%=mod; } ll ans=0; for(int i=1;i<k;i++) ans+=dp[l][i]; if(k<=2) ans=0; cout<<ans<<endl; return 0;}
0 0
- Dp水题
- DP 水题
- dp-水题
- dp水题
- poj1163 dp水题
- hdu 1231 DP水题
- PKU 2704 水题DP
- 养猪(dp水题)
- UVA 11584 DP水题
- UVA 1424 DP水题
- UVA 11552 DP水题
- UVA 1456 DP水题
- dlut1217-dp水题
- 经典DP水题A
- 经典DP水题B
- 经典DP水题G
- 一些 DP 水题
- 经典DP水题C
- 码农与真正程序员的区别
- RGBD-SLAM
- printf函数输出
- 【C#】Message类的属性Msg所关联的消息ID
- sgu136:Erasing Edges
- DP 水题
- 浅析hybrid模式下地支付宝钱包和微信
- IOS开发之UIView总结
- LESSON: Why Excel Cell Exported From Jasper Server Has No Grid Displayed
- Android adb 常用命令
- hashcode()和equals()的不同之处
- java 利用反射获取类,实例化,并执行其内部方法
- 设计模式简介
- 《C陷阱与缺陷》读书笔记