1217. Unlucky Tickets

Time limit: 1.0 second
Memory limit: 64 MB
Strange people live in Moscow! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the first half of digits and the last half of digits. If these two sums are equal, they suppose such a ticket to be a lucky one. A person, who owns the lucky ticket, should dream about something, eat the ticket (no, it’s not made of chocolate, it’s made of paper!) and the dream will come true… At least, they believe it!
Strange people live in St.Petersburg! Each time in the bus, getting a ticket with a 6-digit number, they try to sum up the digits on the odd positions and the digits on the even positions. If these two sums are equal, they suppose such a ticket to be a lucky one. A person, who owns the lucky ticket, should dream about something, eat the ticket (no, even in St. Petersburg lucky tickets are not made of chocolate, they’re made of paper!) and the dream will come true… At least, they believe it!
In the "third Russian capital" — Yekaterinburg — we laugh about such strange ideas. We are practical. We are not superstitious, even a little bit. But we understand that too much luck cannot be good. Thus we consider every ticket, which is lucky both in "Moscow sense" and "St. Petersburg sense" to be unlucky. If we get an unlucky ticket in the bus, we throw it away and leave the bus immediately! Two examples of unlucky tickets are 472175 and 810513.
You are to write a program, which calculates the total number of unlucky N-digit tickets.

Input

The input contains a single even positive integer N (2 ≤ N ≤ 20) — the number of digits in the ticket. Please note, that, for example 00742544 is a valid 8-digit ticket (by the way, it is a St.Petersburg-style lucky ticket).

Output

Your program should output a single integer number — the total number of unlucky N-digit tickets.

Sample

input output
4
100
Problem Author: Leonid Volkov
Problem Source: The Seventh Ural State University collegiate programming contest
Difficulty: 396
 
题意:问n(n为偶数)位数里面,有多少满足1、奇数位之和和偶数位之和相同 2、前一半的数之和等于后一半的数之和
分析:简单的数位dp,dp[i][j][k]表示前i位,前一半比后一半多j,奇数位的和比偶数位的和多k(在数组里记录相对于某个数的偏移量)的有多少。
答案就是dp[n][0][0],暴力转移即可
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = , M = ;
int n;
LL Dp[N][M][M*]; inline void Input() {
scanf("%d", &n);
} inline void Solve() {
int m = n*+, Left, Right;
Left = n/+, Right = n/;
Dp[][][m] = ;
Rep(i, n+)
Rep(j, m)
Rep(k, m*)
if(Dp[i][j][k]) {
int x = k-m, _j, y;
Rep(l, ) {
if(i+ >= Left && l > j) break;
if(i+ <= Right) _j = j+l;
else if(i+ >= Left) _j = j-l;
if((i+)&) y = x+l;
else y = x-l;
//printf("%d %d %d %d %d %d\n", i, j, k-m,i+1, _j, y);
Dp[i+][_j][y+m] += Dp[i][j][k];
}
//printf("%d %d %d %d\n", i, j, k-m, Dp[i][j][k]);
} cout<<Dp[n][][m]<<endl;
} int main() {
#ifndef ONLINE_JUDGE
SetIO("B");
#endif
Input();
Solve();
return ;
}

ural 1217. Unlucky Tickets的更多相关文章

  1. 递推DP URAL 1031 Railway Tickets

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

  2. DP+高精度 URAL 1036 Lucky Tickets

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

  3. Ural 1036 Lucky Tickets

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

  4. URAL 1031. Railway Tickets(spfa)

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

  5. URAL DP第一发

    列表: URAL 1225 Flags URAL 1009 K-based Numbers URAL 1119 Metro URAL 1146 Maximum Sum URAL 1203 Scient ...

  6. ural 1070. Local Time

    1070. Local Time Time limit: 1.0 secondMemory limit: 64 MB Soon the USU team will go to Vancouver to ...

  7. URAL(DP集)

    这几天扫了一下URAL上面简单的DP 第一题 简单递推 1225. Flags #include <iostream> #include<cstdio> #include< ...

  8. URAL 1796. Amusement Park (math)

    1796. Amusement Park Time limit: 1.0 second Memory limit: 64 MB On a sunny Sunday, a group of childr ...

  9. URAL 1036(dp+高精度)

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

随机推荐

  1. NGUI无限滑动

    http://www.unity蛮牛.com/blog-9383-1391.html 最近由于工作需要,就开始研究NGUI滑动.刚开始参考NGUI自带的循环滑动,利用隐藏和显示,提高GPU的渲染,但是 ...

  2. 如何解决Eclipse启动时画面一闪而过

    以前Eclipse都可以正常使用,突然有一天不能启动了,点击图标后启动画面一闪之后就消失了,以下是一些解决方案 1. 找到Eclipse目录下的eclipse.exe,右键点击->发送到桌面快捷 ...

  3. 18个网站SEO建议

    第一位专家是Autotrader公司的搜索市场经理Dewi Nawasari,她认为SEO就是优化网站,以吸引你的目标客户的过程.她的建议如下: 1.创建良好的引导链接 要把用户的使用过程尽量的简化, ...

  4. mysql 多表连接

    现有表R,S如下: 笛卡尔积 select * from R,S; 结果: 注:不需要任何条件.结果为两张表函数相乘(3x3=9). 自连接 select e.empno,e.ename,m.empn ...

  5. 【Web】关于URL中文乱码问题

    关于URL编码                                        一.问题的由来 URL就是网址,只要上网,就一定会用到.                          ...

  6. 【SpringMVC】SpringMVC系列5之@RequestHeader 映射请求头属性值

    5.@RequestHeader 映射请求头属性值 5.1.概述 请求头包含了若干个属性,服务器可据此获知客户端的信息,通过 @RequestHeader 即可将请求头中的属性值绑定到处理方法的入参中 ...

  7. TypeError: document.formname.submit is not a function

    <form name="formname" ...> .... <input name="submit" type="submit& ...

  8. 【转】mybatis实战教程(mybatis in action)之八:mybatis 动态sql语句

    转自:除非申明,文章均为一号门原创,转载请注明本文地址,谢谢! 转载地址:http://blog.csdn.net/kutejava/article/details/9164353#t5 1. if ...

  9. 基于cocoStudio的UIListView的可以左右滑动翻页的ListView

    //WidgetSlideListView.h class WidgetEaseInListView : public cocos2d::gui::UIListView { public: stati ...

  10. iOS 中关于ViewController总结

    以前写程序时,经常被旋转问题弄的头疼,今天为了解决这个问题,偶然看到了苹果官方文档 View Controller Programming Guide for iOS. 这才发现这个必读的资料!以前许 ...