UVALive 6529 Eleven 区间dp
题目链接: option=com_onlinejudge&Itemid=8&page=show_problem&problem=4540">点击打开链接
题意:
给定一个数,又一次排列这个数的各个位置使得
1、无前导0
2、能被11整除
问:
有多少种组合方法
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 1000000000 + 7;
const int N = 100+2;
const int L = 50+2;
const int M = L*9; char s[N];
int x, sum, len, app[10];
int C[N][N], d[10][L][M], g[N][N], tot[12]; int c(int x, int y) {
if (~C[x][y])
return C[x][y];
if (x == 1 || y==0)
return C[x][y] = 1;
C[x][y] = 0;
for (int i = 0; i <= y; ++i)
C[x][y] = (C[x][y] + c(x-1, y-i))%mod;
return C[x][y];
}
void work() {
int v;
len = strlen(s);
sum = 0;
memset(app, 0, sizeof app);
for (int i = 0; i < len; ++i) {
++ app[s[i]-'0'];
sum += s[i]-'0';
}
tot[0] = 0;
for (int i = 1; i <= 9; ++i)
tot[i] = tot[i-1] + app[i];
x = (len+1)/2;
memset(d, 0, sizeof d);
d[0][0][0] = 1;
for (int i = 0; i <= 8; ++i)
for (int j = 0; j <= x && j <= tot[i]; ++j)
for (int s = 0; s <= j*9; ++s)
if (d[i][j][s] > 0)
for (int k = 0; k <= app[i+1] && k+j <= x; ++k) {
v = (ll)d[i][j][s] * c(j+1,k) % mod;
v = (ll)v*g[len-x-tot[i]+j][app[i+1]-k]%mod;
d[i+1][j+k][s+k*(i+1)] = (d[i+1][j+k][s+k*(i+1)] + v)%mod;
}
int ans = 0;
for (int j = 1; j <= x; ++j)
for (int s = 0; s <= j*9; ++s)
if (d[9][j][s] > 0 && abs(sum-s-s) % 11 == 0) {
int k = x - j;
if (k > app[0])
continue;
ans += (ll)d[9][j][s] * c(j,k) % mod;
ans %= mod;
}
printf("%d\n", ans);
}
int main() {
memset(C, -1, sizeof C);
memset(g, 0, sizeof g);
for (int i = 0; i < N; ++i) {
g[i][0] = g[i][i] = 1;
for (int j = 1 ; j < i; ++j)
g[i][j] = (g[i-1][j] + g[i-1][j-1])%mod;
}
while (~scanf("%s", s))
work();
return 0;
}
UVALive 6529 Eleven 区间dp的更多相关文章
- UVALive - 6529 找规律+dp
题目链接: http://acm.hust.edu.cn/vjudge/problem/47664 Eleven Time Limit: 5000MS 问题描述 In this problem, we ...
- UVALive 4987---Evacuation Plan(区间DP)
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- uvalive 6938 区间dp
看到n范围和给的区间看着就像区间dp 然后怎么cmp感觉都没法进行区间合并 n的300误导了下 没有注意离散化之后对时间可以dp 然而这个dp感觉不太经得起证明的样子... dp[i][j] -> ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
随机推荐
- 【大视野入门OJ】1099:歌德巴赫猜想
Description 歌德巴赫猜想大家都很熟悉吧?给一个数,能够分解成两个素数的和.现在要给你一个n,6 <= n < 1000000,让你求他会分解成哪两个素数?如果存在多组解,则要求 ...
- MTK平台源码 mt6589-jb3-x_20131122
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
- Codeforces 500 E. New Year Domino
\(>Codeforces \space 500 E. New Year Domino<\) 题目大意 : 数轴上有序排列着 \(n\) 块多米诺骨牌, 第 \(i\) 块骨牌坐标为 \( ...
- 【左偏树+延迟标记+拓扑排序】BZOJ4003-城池攻占
[题目大意] 有n个城市构成一棵树,除1号城市外每个城市均有防御值h和战斗变化参量a和v. 现在有m个骑士各自来刷副本,每个其实有一个战斗力s和起始位置c.如果一个骑士的战斗力s大于当前城市的防御值h ...
- Codeforces Beta Round #1 C. Ancient Berland Circus 计算几何
C. Ancient Berland Circus 题目连接: http://www.codeforces.com/contest/1/problem/C Description Nowadays a ...
- ubuntu BCM43142 lenovo网卡驱动安装(Broadcom)
ubuntu13.10 lenovo网卡驱动安装(Broadcom) ubuntu当月刚出了13.10版本,在升级了操作系统版本后无法搜索无线热点,联想官网提供的驱动下载都是为windows准备的 ...
- 监控RTSP 流
rtsp://admin:admin12345@192.168.0.100/live1.sdp
- win7与Ubuntu 13.04双系统修改启动项顺序
在在win7下安装了Ubuntu 13.04后,在grub中,win7启动想是最后一个,为了把win7设置为默认启动项,需要更改grub设置.google了半天,发现更改/etc /default/g ...
- 初步学习React Router 4.0
React Router 4.0 是react官方推荐的路由库.4是已经正式发布的最新版本. 初始化项目启动之后: npm run eject 弹出配置文件.自定义配置webpack 查看下pac ...
- OpenShift蓝绿及灰度部署
内容转自https://blog.csdn.net/jj_tyro/article/details/80136316, 并不断补充,感谢作者. 1.蓝绿部署 蓝绿部署实现的是全流量切换,适合于在测试完 ...