LightOJ 1021 - Painful Bases(dp)
2015-11-09 20:48
585 查看
题目链接:LightOJ 1021 - Painful Bases
代码
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn = 25; const int maxs = 1<<17; typedef long long ll; int base, K; char s[maxn]; ll dp[maxs][maxn]; int idx(char ch) { if (ch >= '0' && ch <= '9') return ch - '0'; else return ch - 'A' + 10; } ll solve () { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; int n = strlen(s); for (int i = 0; i < (1<<n); i++) { for (int j = 0; j < n; j++) if ((i&(1<<j)) == 0) { for (int k = 0; k < K; k++) { int v = (k * base + idx(s[j])) % K; dp[i|(1<<j)][v] += dp[i][k]; } } } return dp[(1<<n)-1][0]; } int main () { int cas; scanf("%d", &cas); for (int kcas = 1; kcas <= cas; kcas++) { scanf("%d%d%s", &base, &K, s); printf("Case %d: %lld\n", kcas, solve()); } return 0; }
相关文章推荐
- http://blog.csdn.net/jadyer/article/details/6013743
- hdu 3264 Open-air shopping malls(几何)
- hdu4770 Lights Against Dudely
- Gradle project sync failed. Please fix your project and try again.
- 正确使用Block避免Cycle Retain和Crash
- Scala初学者学习资料:main(String[])
- 运行Scala应用 Main方法
- .NET 4.0 使用 asyn await
- 父进程等待子进程结束 waitpid wait
- Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON
- git常见错误failed to push some refs to
- NovaException: Unexpected vif_type=binding_failed
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
- 重新启动SNMP服务解决监控AIX系统问题
- Referenced file contains errors 解决方法 (转载地址:http://blog.sina.com.cn/s/blog_6a6b141001011xhn.html)
- Package should contain a content type part [M1.13]
- IntelliJ IDEA 官方网站 http://www.jetbrains.com/idea/
- wait sleep区别
- Goldengate 源端 dump进程无法启动报;scoket buffer size set to xxx connect failed to targetIP:7819,error
- mybtais 映射文件参数简写