hdu1483 钥匙计数之一(数位dp)
2016-07-18 13:54
246 查看
钥匙计数之一
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1616 Accepted Submission(s): 694
Problem Description
一把锁匙有N个槽,槽深为1,2,3,4。每锁匙至少有3个不同的深度且至少有1对相连的槽其深度之差为3。求这样的锁匙的总数。
Input
本题无输入
Output
对N>=2且N<=31,输出满足要求的锁匙的总数。
Sample Output
N=2: 0
N=3: 8
N=4: 64
N=5: 360
..
..
..
..
..
..
..
N=31: …
直接数位dp,看了网上的数学找规律,真心觉得叼,然而我太菜,不会玄学推公式,老老实实用数位dp,还有用状压dp写的,膜。
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1616 Accepted Submission(s): 694
Problem Description
一把锁匙有N个槽,槽深为1,2,3,4。每锁匙至少有3个不同的深度且至少有1对相连的槽其深度之差为3。求这样的锁匙的总数。
Input
本题无输入
Output
对N>=2且N<=31,输出满足要求的锁匙的总数。
Sample Output
N=2: 0
N=3: 8
N=4: 64
N=5: 360
..
..
..
..
..
..
..
N=31: …
直接数位dp,看了网上的数学找规律,真心觉得叼,然而我太菜,不会玄学推公式,老老实实用数位dp,还有用状压dp写的,膜。
#include<bits/stdc++.h> using namespace std; #define read(T) int T;\ scanf("%d",&(T));\ while(T--) #define si(x) scanf("%d",&(x)) #define sii(x,y) scanf("%d%d",&(x),&(y)) #define cls(x,y) memset((x),(y),sizeof((x))); #define sl(x) scanf("%lld",&(x)) typedef long long LL; typedef unsigned long long ULL; const int maxint=((~((unsigned)(0)))>>1); const LL maxll=((~((unsigned long long)(0)))>>1); const int maxn=105; const int maxm=105; const int maxk=105; LL dp[31][35][5][2]; LL dfs(int pos,int num,int last,int f) { if(pos<0) { if((((num>>2)&1)+((num>>3)&1))>=1&&f==1)return 1LL; return 0LL; } if(~dp[pos][num][last][f])return dp[pos][num][last][f]; LL ans=0; for(int i=1; i<=4; ++i) { ans+=dfs(pos-1,num|(1<<i),i,f||(last&&(abs(last-i)>=3))); } return dp[pos][num][last][f]=ans; } int main() { // freopen("Myans.txt","w",stdout); cls(dp,-1) for(int n=2; n<=31; ++n) { cout<<"N="<< n << ": " << dfs(n-1,0,0,0) << endl; } return 0; }
相关文章推荐
- LAMP 环境搭建 C7
- Unity3D——使用UGUI为角色添加名字和血条
- QT中QtConcurrent创建并行线程的方法
- 7月书讯:看风景的人
- Android调用系统剪裁参数
- 关于执行ndk-build后的代码
- HDU 4725 The Shortest Path in Nya Graph(SPFA)
- JS中的!=、== 、!==、===的用法和区别
- 完整的登录、注册页面
- git使用
- 安卓注解框架 annotation
- 设置div水平垂直居中
- Java中JDBC的事务问题
- 跳转到指定界面
- ubuntu dns unknown解决办法
- 以SpringMVC框架为中心疯狂扩展-08、ActiveMQ收发Json格式的数据
- 老男孩Linux运维决心书
- android 通讯录侧边快速索引
- 【iOS】UIImageView 点击事件
- android studio :app:transformClassesWithDexForDebug finished with non-zero exit value 1