DP+高精度 URAL 1036 Lucky Tickets
/*
题意:转换就是求n位数字,总和为s/2的方案数
DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k];
高精度直接拿JayYe的:)
异或运算的规则:
0⊕0=0,0⊕1=1
1⊕0=1,1⊕1=0
口诀:相同取0,相异取1
*/
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std; const int numlen = ;
const int numbit = ;
const int addbit = ;
const int maxn = numlen/numbit + ; struct bign {
int len, s[numlen];
bign() {
memset(s, , sizeof(s));
len = ;
}
bign(int num) { *this = num; }
bign(const char *num) { *this = num; }
bign operator = (const int num) {
char s[numlen];
sprintf(s, "%d", num);
*this = s;
return *this;
}
bign operator = (const char *num){
int clen = strlen(num);
while(clen > && num[] == '') num++, clen--;
len = ;
for(int i = clen-;i >= ; i -= numbit) {
int top = min(numbit, i+), mul = ;
s[len] = ;
for(int j = ;j < top; j++) {
s[len] += (num[i-j]-'')*mul;
mul *= ;
}
len++;
}
deal();
return *this;
}
void deal() {
while(len > && !s[len-]) len--;
}
bign operator + (const bign &a) const {
bign ret;
ret.len = ;
int top = max(len, a.len), add = ;
for(int i = ;add || i < top; i++) {
int now = add;
if(i < len) now += s[i];
if(i < a.len) now += a.s[i];
ret.s[ret.len++] = now%addbit;
add = now/addbit;
}
return ret;
}
bign operator * (const bign &a)const {
bign ret;
ret.len = len + a.len;
for(int i = ;i < len; i++) {
int pre = ;
for(int j = ;j < a.len; j++) {
int now = s[i]*a.s[j] + pre;
pre = ;
ret.s[i+j] += now;
if(ret.s[i+j] >= addbit) {
pre = ret.s[i+j]/addbit;
ret.s[i+j] -= pre*addbit;
}
}
if(pre) ret.s[i+a.len] = pre;
}
ret.deal();
return ret;
}
}dp[][];
istream& operator >> (istream &in, bign &x) {
string s;
in >> s;
x = s.c_str();
return in;
}
ostream& operator << (ostream &out, const bign &x) {
printf("%d", x.s[x.len-]);
for(int i = x.len-;i >= ; i--) printf("%04d", x.s[i]);
return out;
} int main(void) //URAL 1036 Lucky Tickets
{
//freopen ("W.in", "r", stdin); int n, s;
while (scanf ("%d%d", &n, &s) == )
{
if (s & ) {puts (""); continue;} dp[][] = ;
int cur = ;
for (int i=; i<=n; ++i)
{
for (int j=; j<=s/; ++j) dp[cur^][j] = ;
for (int j=; j<=; ++j)
{
for (int k=; k+j<=s/; ++k)
dp[cur^][k+j] = dp[cur^][k+j] + dp[cur][k];
}
cur ^= ;
} cout << dp[cur][s/] * dp[cur][s/] << endl;
} return ;
}
DP+高精度 URAL 1036 Lucky Tickets的更多相关文章
- Ural 1036 Lucky Tickets
Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ...
- URAL 1036(dp+高精度)
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- Codeforces Gym 100418J Lucky tickets 数位DP
Lucky ticketsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...
- 递推DP URAL 1031 Railway Tickets
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/d ...
- 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
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3247 Accepted: 2136 Des ...
- 1166 矩阵取数游戏[区间dp+高精度]
1166 矩阵取数游戏 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description [ ...
- bzoj 1089 [SCOI2003]严格n元树(DP+高精度)
1089: [SCOI2003]严格n元树 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 1250 Solved: 621[Submit][Statu ...
随机推荐
- Android经常使用的工具类
主要介绍总结的Android开发中经常使用的工具类,大部分相同适用于Java. 眼下包含HttpUtils.DownloadManagerPro.ShellUtils.PackageUtils. Pr ...
- 完美解决android显示gif
今天是周5啊.纠结了一天.android显示gif,没该控件 网上找开源项目 找到个viewgif.该作者在各大站点都在推荐自己的项目...好吧.用下吧. . . . 结果呢: 图片略微一大就 内存溢 ...
- 责任链模式-Chain of Responsibility
责任链模式:使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系.将这个对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. 责任链模式结构图: 代码实现: 责任链模式 ...
- A Practical Introduction to Blockchain with Python
A Practical Introduction to Blockchain with Python // Adil Moujahid // Data Analytics and more http: ...
- MTK平台下Battery驱动分析
主要涉及代码: Kernel: kernel-3.10\drivers\power\mediatek\ kernel-3.10\drivers\misc\mediatek\mach\mt6580\&l ...
- Ghost wenjian目录
SOAMANAGER打不开网页,需要配置ghost 文件, C:\Windows\System32\drivers\etc
- Spark理论学习笔记(一)
1.调度 分为FIFO和FAIR两种模式 创建调度池:sc.setLocalProperty("spark.scheduler.pool", "pool6") ...
- #import @import #include
1.在xcode5以后 ,Replace #import <Cocoa/Cocoa.h> with @import Cocoa; 在这之前 必须手动设置一下才能用. 2.#import 与 ...
- linux 一个超简单的makefile
makefile 自动化变量: $@ : 规则的目标文件名 例如:main:main.o test.o g++ -Wall -g main.o test. ...
- bzoj4169: Lmc的游戏
终于有道我会的了... int f[2][maxn],g[2][maxn],tot[maxn];//构造叶子编号时希望最大/小result 先手取子树最小/大的编号的排名 tot是子树中叶子个数 如果 ...