Ural 1036 Lucky Tickets
Lucky Tickets
This problem will be judged on Ural. Original ID: 1036
64-bit integer IO format: %lld Java class name: (Any)
Input
Output
Sample Input
2 2
Sample Output
4
Hint
#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的更多相关文章
- DP+高精度 URAL 1036 Lucky Tickets
题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...
- URAL 1036(dp+高精度)
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- ural 1217. Unlucky Tickets
1217. Unlucky Tickets Time limit: 1.0 secondMemory limit: 64 MB Strange people live in Moscow! Each ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- POJ 2346:Lucky tickets
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3247 Accepted: 2136 Des ...
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- 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 ...
- 递推DP URAL 1031 Railway Tickets
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...
- URAL 1031. Railway Tickets(spfa)
题目链接 不知为何会在dp里呢...INF取小了,2Y. #include <cstring> #include <cstdio> #include <string> ...
随机推荐
- bzoj 1725: [Usaco2006 Nov]Corn Fields牧场的安排【状压dp】
压一维状态,转移时把符合条件的上一行加上 #include<iostream> #include<cstdio> using namespace std; const int ...
- 源码阅读之LinkedHashMap(JDK8)
概述 LinkedHashMap继承自HashMap,实现了Map<K,V>接口.其内部还维护了一个双向链表,在每次插入数据,或者访问.修改数据时,会增加节点.或调整链表的节点顺序.以决定 ...
- web界面bug-临时
一.登录页面 二.首页 三.项目 四.项目池 五.专家管理 六.审批 七.日/周报 八.设置
- 例题 5-1 STL
Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on the ...
- http2及server push
本文主要研究下java9+springboot2+undertow2启用http2及server push maven <parent> <groupId>org.spri ...
- mongodb的安装以及客户端
mongodb是一种非关系型的数据库,与传统的sql有很大的不同,但都是用于数据管理的,本人也是初学,很多地方都是模仿,在这里只是记录本人初次安装mongodb和客户端,记录一下安装的步骤,以便以后用 ...
- Matlab vs Python 作图
-- Matlab 作图示例 x=-3:0.00003:3; y1=sin(x)./x; y2=x./sin(x); plot(x,y1,x,y2); -- Python 作图示例 import nu ...
- Hadoop Hive概念学习系列之HiveQL编译基础(十)
由客户端提交的HiveQL语句将最终被转换为一个或多个MapReduce任务并提交由Hadoop执行.不包含聚合和连接的简单SELECT语句可以使用一个单独的只包含Map阶段的任务实现.使用GROUP ...
- ES6:Generator函数(1)
Generator函数是ES6提供的一种异步编程解决方案.它会返回一个遍历器对象 function* helloWorldGenerator(){ yield “hello”; yield “worl ...
- 前端--2、CSS基础
CSS的部分: CSS四种类引入方式(了解) style的定义原则: 基本选择器 示例: 层级选择器 组合选择器 后代选择器 ★ 子代选择器 毗邻选择器 普通兄弟选择器 “与”选择器 ★ “或”选择器 ...