Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

You are given a number 1 ≤ N ≤ 50. Every ticket has its 2 N-digit number. We call a ticket lucky, if the sum of its first N digits is equal to the sum of its last N digits. You are also given the sum of ALL digits in the number. Your task is to count an amount of lucky numbers, having the specified sum of ALL digits.

Input

Two space-separated numbers: N and S. Here S is the sum of all digits. Assume that 0 ≤ S ≤ 1000.

Output

The amount of lucky tickets.

Sample Input

input output
2 2
4

Hint

The tickets are 0101, 0110, 1001, 1010 in the example above
求前N位与后N位各个位和相等且总和等于S的2N位数的个数。
注意:每个位上的数字是0-9也就是十进制
状态转移方程:dp[i][j]=sum(dp[i-1][j-k],0<=k<=9)。可想而知最后的数一定会很大。所有操作都用高精度来做
#include<stdio.h>
#include<cstring>
#include<iostream>
using namespace std;
int dp[][][];//第100位存的是数据的长度
int n,tot;
void add(int sum[],int num[])
{
int i,j,temp[];
int len1=sum[],len2=num[];
int max=len1>len2 ? len1:len2;
int jin=;
for(i=;i<max;i++){
int m=jin+sum[i]+num[i];
if(m>=) {jin=;m-=;}
else jin=;
temp[i]=m;
}
if(jin) temp[i++]=jin;
for(j=;j<i;j++)
sum[j]=temp[j];
sum[]=i;
}
void muti_dan(int num[],int data[],int n,int h)
{
int temp[],i,j;
memset(temp,,sizeof(temp));
int len=num[];
int jin=;
for(i=;i<len;i++){
int m=num[i]*n+jin;
jin=m/;
if(jin)m-=jin*;
temp[i]=m;
}
if(jin) temp[i++]=jin;
data[-h]=i;
for(j=;j<i;j++){
data[j]=temp[j];
}
}
void multi(int num[],int num1[])
{
int temp[],sum[],i,j;
memset(sum,,sizeof(sum));
int len1=num[],len2=num1[];
for(j=;j<len2;j++){
memset(temp,,sizeof(temp));
muti_dan(num,&temp[j],num1[j],j);
temp[]+=j;
add(sum,temp);
}
for(i=;i<sum[];i++){
num[i]=sum[i];
}
num[]=sum[];
}
void display(int num[])
{
int len=num[];
for(int i=len-;i>;i--)
cout<<num[i];
cout<<num[]<<endl;
}
void solve()
{
int i,j,k;
if(tot%) {printf("0\n");return;}
int sum=tot/;
memset(dp,,sizeof(dp));
for(i=;i<;i++) {
dp[][i][]=;
dp[][i][]=;
} for(i=;i<n-;i++){
for(j=;j<=sum;j++){
for(k=;k<=&&j+k<=sum;k++){
add(dp[i+][j+k],dp[i][j]);
}
}
} multi(dp[n-][sum],dp[n-][sum]);
display(dp[n-][sum]);
}
int main(void)
{
while(cin>>n>>tot){
solve();
}
return ;
}

URAL 1036(dp+高精度)的更多相关文章

  1. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  2. 1166 矩阵取数游戏[区间dp+高精度]

    1166 矩阵取数游戏 2007年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description [ ...

  3. bzoj 1089 [SCOI2003]严格n元树(DP+高精度)

    1089: [SCOI2003]严格n元树 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 1250  Solved: 621[Submit][Statu ...

  4. CF23 E. Tree 树形dp+高精度

    题目链接 CF23 E. Tree 题解 CF竟让卡常QAQ dp+高精度 dp[x][j]表示以x为根的子树,x所属的联通块大小为j,的最大乘积(不带j这块 最后f[x]维护以x为根的子树的最大答案 ...

  5. 【bzoj2764】[JLOI2011]基因补全 dp+高精度

    题目描述 在生物课中我们学过,碱基组成了DNA(脱氧核糖核酸),他们分别可以用大写字母A,C,T,G表示,其中A总与T配对,C总与G配对.两个碱基序列能相互匹配,当且仅当它们等长,并且任意相同位置的碱 ...

  6. poj 1205 :Water Treatment Plants (DP+高精度)

    题意:有n个城市,它们由一个污水处理系统连接着,每个城市可以选择 1.将左边城市过来的污水和右边城市过来的污水连同本身的污水排到河里  >V< 2.将左边来的污水连同自己的污水排到右边   ...

  7. URAL 1012 K-based Numbers. Version 2(DP+高精度)

    题目链接 题意 :与1009一样,不过这个题的数据范围变大. 思路:因为数据范围变大,所以要用大数模拟,用java也行,大数模拟也没什么不过变成二维再做就行了呗.当然也可以先把所有的都进行打表,不过要 ...

  8. Ural 1036 Lucky Tickets

    Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...

  9. POJ 1625 Censored!(AC自动机+DP+高精度)

    Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Descrip ...

随机推荐

  1. 提醒录入BOM更改原因

    应用 Oracle Bill Of   Materiel 层 Level Function 函数名 Funcgtion Name BOM_BOMFDBOM 表单名 Form Name BOMFDBOM ...

  2. [方法] ubuntu12.04开启root账户

    ubuntu 12.04使用LightDM显示管理器,默认禁止root账户登录. 通过修改/etc/lightdm/lightdm.con文件可以打开root登录权限. 方法很简单,只要在lightd ...

  3. 转 批处理 %~dp0的意义

    http://nealcai.iteye.com/blog/1685192 http://blog.csdn.net/caz28/article/details/7448677 http://stac ...

  4. Java面试题之六

    三十一.如何取小数点前两位,并四舍五入. package com.lovo; public class TestDot2 { // 方法1 public void test1(double c) { ...

  5. UVAlive 2911 Maximum(贪心)

    Let x1, x2,..., xm be real numbers satisfying the following conditions: a) -xi ; b) x1 + x2 +...+ xm ...

  6. xcode UIButton创建、监听按钮点击、自定义按钮 、状态 、内边距

    代码创建 //创建UIButton UIButton * btnType=[[UIButton alloc]init]; //设置UIControlStateNormal状态下的文字颜色 [btnTy ...

  7. char、varchar和nvarchar的区别

    首先char.varchar和nvarchar.text.ntext都是数据库中的文本数据类型,再区分区分var前缀.n前缀的区别.而text.ntext已经普遍被varchar(MAX)和nvarc ...

  8. Dearmweaver CS6 如何添加emmet 插件

     一.关于emmet插件 已经接触前端工具的小伙伴们早听说过这个插件的鼎鼎大名了吧,emmet可以说是前端工程师的利器,就连老牌dreamweaver 都可以支持,我们怎么好意思拒绝这个好东西呢? 有 ...

  9. Win10下Genymotion无法正常使用的解决方法

    原Win7下安装配置的genymotion正常使用,Eclipse的Genymotion插件也可以正常运行.系统升级后,忽然就不work了. 折腾了一天试了各种方式,网上的例子也五花八门.最后还是找到 ...

  10. EasyUI easyui-combobox 重复发送请求

    今天在做个EasyUI easyui-combobox 下拉框动态连级的时候发现在选择一个值的时候发送了两次请求,这有点逆天呀~!!反人类~!必须和谐一开始以为是重复绑定了,重新审核了代码 确定没有~ ...