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. 解决:未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0

    开发环境:Microsoft Visual Studio 2013 MVC4.0 使用SignalR的过程中随着版本的升级,其它程序集也跟着升级,如Newtonsoft.Json,一般编译的时候,如果 ...

  2. [Leetcode][Python]25: Reverse Nodes in k-Group

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 25: Reverse Nodes in k-Grouphttps://oj. ...

  3. poj1580---欧几里得算法(辗转相除法)

    #include<stdio.h> #include<string.h> #include<string.h> ],str2[]; int len; int cal ...

  4. padding-top、margin-top和top的区别

    padding-top:10px;是指容器内的内容距离容器的顶部有10个像素,是包含在容器内的: margin-top:10px;是指容器本身的顶部距离其他容器有10个像素,不包含在容器内: top: ...

  5. ReactNative实现通知监听事件

    事例1: 只在rn里面发送和接受消息. A界面: import {DeviceEventEmitter} from 'react-native'; //... componentDidMount(){ ...

  6. uva10617 - Again Palindrome(dp)

    再次回文 输入:标准输入 输出:标准输出 时间限制: 2秒 是àpalindorme的读取相同的从左边,因为它从右侧的一个或多个字符的序列.例如,Ž,TOT和女士的 回文,但是,ADAM是不是. 给定 ...

  7. Java操作mongoDB2.6的常见API使用方法

    对于mongoDB而言,学习方式和学习关系型数据库差不太多 開始都是学习怎样insert.find.update.remove,然后就是分页.排序.索引,再接着就是主从复制.副本集.分片等等 最后就是 ...

  8. sql server group by having 之复习篇

    where 与 having 之间的差别在于where 是分组前的过滤,而having是分组后的过滤 Group By中Select指定的字段限制 示例3 select 类别, sum(数量) as ...

  9. history.js 一个无刷新就可改变浏览器栏地址的插件(不依赖jquery)

    示例: http://browserstate.github.io/history.js/demo/     简介   HTML4有一些对浏览历史的前进后退API的支持如:   window.hist ...

  10. 基于Nodejs开发的web即时聊天工具

    由于公司需要开发web即时聊天的功能,开始时我们主要的实施方法是用jquery的ajax定时(10秒)轮询向服务器请求,由于是轮询请求,对 服务器的压力比较大.我们网站上线的时间不长,访问量不是很大, ...