Lucky Tickets

Time Limit: 2000ms
Memory Limit: 16384KB

This problem will be judged on Ural. Original ID: 1036
64-bit integer IO format: %lld      Java class name: (Any)

 
You are given a number 1 ≤ N ≤ 50. Every ticket has its 2N-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

2 2

Sample Output

4

Hint

The tickets are 0101, 0110, 1001, 1010 in the example above
 
解题:动态规划$dp[i][j]表示处理到了第i位,且前i位的和为j的方案数$
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAXN 100
struct HP {
int len,s[MAXN];
HP() {
memset(s,,sizeof(s));
len = ;
}
HP operator=(const char *num) { //字符串赋值
len = strlen(num);
for(int i = ; i < len; i++) s[i] = num[len-i-]-'';
}
HP operator=(int num) { //int 赋值
char s[MAXN];
sprintf(s,"%d",num);
*this = s;
return *this;
}
HP(int num) {
*this = num;
}
HP(const char*num) {
*this = num;
}
string str()const { //转化成string
string res = "";
for(int i = ; i < len; i++) res = (char)(s[i]+'') + res;
if(res == "") res = "";
return res;
}
HP operator +(const HP& b) const {
HP c;
c.len = ;
for(int i = ,g = ; g||i < max(len,b.len); i++) {
int x = g;
if(i < len) x += s[i];
if(i < b.len) x += b.s[i];
c.s[c.len++] = x%;
g = x/;
}
return c;
}
void clean() {
while(len > && !s[len-]) len--;
} HP operator *(const HP& b) {
HP c;
c.len = len + b.len;
for(int i = ; i < len; i++)
for(int j = ; j < b.len; j++)
c.s[i+j] += s[i]*b.s[j];
for(int i = ; i < c.len-; i++) {
c.s[i+] += c.s[i]/;
c.s[i] %= ;
}
c.clean();
return c;
}
HP operator - (const HP& b) {
HP c;
c.len = ;
for(int i = ,g = ; i < len; i++) {
int x = s[i]-g;
if(i < b.len) x -= b.s[i];
if(x >= ) g = ;
else {
g = ;
x += ;
}
c.s[c.len++]=x;
}
c.clean();
return c;
}
HP operator /(const HP &b) {
HP c, f = ;
for(int i = len-; i >= ; i--) {
f = f*;
f.s[] = s[i];
while(f >= b) {
f = f - b;
c.s[i]++;
}
}
c.len = len;
c.clean();
return c;
}
HP operator % (const HP &b) {
HP r = *this / b;
r = *this - r*b;
return r;
}
HP operator /= (const HP &b) {
*this = *this / b;
return *this;
}
HP operator %= (const HP &b) {
*this = *this % b;
return *this;
}
bool operator < (const HP& b) const {
if(len != b.len) return len < b.len;
for(int i = len-; i >= ; i--)
if(s[i] != b.s[i]) return s[i] < b.s[i];
return false;
}
bool operator > (const HP& b) const {
return b < *this;
}
bool operator <= (const HP& b) {
return !(b < *this);
}
bool operator == (const HP& b) {
return !(b < *this) && !(*this < b);
}
bool operator != (const HP &b) {
return !(*this == b);
}
HP operator += (const HP& b) {
*this = *this + b;
return *this;
}
bool operator >= (const HP &b) {
return *this > b || *this == b;
}
};
istream& operator >>(istream &in, HP& x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator <<(ostream &out, const HP& x) {
out << x.str();
return out;
}
HP dp[][];
int main(){
dp[][] = ;
for(int i = ; i < ; ++i)
for(int j = ; j <= i*; ++j)
for(int k = ; k < ; ++k)
dp[i][j + k] = dp[i][j + k] + dp[i-][j];
int n,s;
while(~scanf("%d%d",&n,&s)){
if(s&) puts("");
else cout<<dp[n][s>>]*dp[n][s>>]<<endl;
}
return ;
}

Ural 1036 Lucky Tickets的更多相关文章

  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. URAL 1036(dp+高精度)

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

  3. ural 1217. Unlucky Tickets

    1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...

  4. POJ-2346 Lucky tickets(线性DP)

    Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...

  5. POJ 2346:Lucky tickets

    Lucky tickets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3247   Accepted: 2136 Des ...

  6. Codeforces Gym 100418J Lucky tickets 数位DP

    Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  7. CF1096. G. Lucky Tickets(快速幂NTT)

    All bus tickets in Berland have their numbers. A number consists of n digits (n is even). Only k dec ...

  8. 递推DP URAL 1031 Railway Tickets

    题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...

  9. URAL 1031. Railway Tickets(spfa)

    题目链接 不知为何会在dp里呢...INF取小了,2Y. #include <cstring> #include <cstdio> #include <string> ...

随机推荐

  1. kernel信息及其相关命令

    内核 linux内核是单内核体系设计.但充分借鉴了微内核设计体系的优点,为内核引入模块化机制 内核组成部分: kernel: 内核核心,一般为bzImage,通常在/boot 目录下,名称为vmlin ...

  2. 基于PHP自带的mail函数实现发送邮件以及带有附件的邮件功能

    PHPmail函数简介 bool mail ( string $to , string $subject , string $message [, string $additional_headers ...

  3. Google C++编程规范 – 第十九条 -《前置声明》

    转自:http://roclinux.cn/?p=3285 本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc wu == [规范] ...

  4. webservice 权限控制

    webservice 如何限制访问,权限控制?1.服务器端总是要input消息必须携带用户名.密码信息 如果不用cxf框架,SOAP消息(xml片段)的生成.解析都是有程序员负责 2.拦截器 为了让程 ...

  5. python自动化测试学习笔记-9python的日志模块

    参考 logging模块,用来处理python中的日志: import logging logging.debug('debug')logging.info('info')logging.warnin ...

  6. spring的依赖注入如何降低了耦合

    依赖注入:程序运行过程中,如需另一个对象协作(调用它的方法.访问他的属性时),无须在代码中创建被调用者,而是依赖于外部容器的注入 看过一些比较好的回答 1.一个人(Java实例,调用者)需要一把斧子( ...

  7. uiautomatorviewer详解

    一,uiautomatorviewer是什么? Android 4.1发布的,uiautomator是用来做UI测试的.也就是普通的手工测试,点击每个控件元素 看看输出的结果是否符合预期.比如 登陆界 ...

  8. 383 Ransom Note 赎金信

    给定一个赎金信 (ransom) 字符串和一个杂志(magazine)字符串,判断第一个字符串ransom能不能由第二个字符串magazines里面的字符构成.如果可以构成,返回 true :否则返回 ...

  9. Http请求1

    package Test; import java.io.IOException; import java.io.InputStreamReader; import java.net.URISynta ...

  10. 用antlr4来实现《按编译原理的思路设计的一个计算器》中的计算器

    上次在公司内部讲<词法分析——使用正则文法>是一次失败的尝试——上午有十几个人在场,下午就只来了四个听众. 本来我还在构思如何来讲“语法分析”的知识呢,但现在看来已不太可能. 这个课程没有 ...