URAL 1044 Lucky Tickets. Easy!

算是个动态规划,统计和

sum[位数][差值]

构建个虚拟数组写起来就顺多了

 1 import java.util.Scanner;
 2
 3 public class P1044
 4 {
 5     private static int save[][] = new int[10][100];
 6
 7     private static int getSum(int n, int deta)
 8     {
 9         return save[n][deta + 50];
10     }
11
12     private static void addSum(int n, int deta, int sum)
13     {
14         save[n][deta + 50] += sum;
15     }
16
17     public static void main(String args[])
18     {
19         addSum(0, 0, 1);
20         for (int i = 0; i <= 6; i++)
21             for (int deta = -36; deta <= 36; deta++)
22                 if (getSum(i, deta) != 0)
23                     for (int x = 0; x <= 9; x++)
24                         for (int y = 0; y <= 9; y++)
25                             addSum(i + 2, deta + x - y, getSum(i, deta));
26         try (Scanner cin = new Scanner(System.in))
27         {
28             while (cin.hasNext())
29             {
30                 int n = cin.nextInt();
31                 System.out.println(getSum(n, 0));
32             }
33         }
34     }
35 }
时间: 2024-10-07 12:01:17

URAL 1044 Lucky Tickets. Easy!的相关文章

寒假集训.Lucky Tickets. Easy!

Lucky Tickets. Easy! Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Background The public transport administration of Ekaterinburg is anxious about the fact that passengers don't like to pay for

DP+高精度 URAL 1036 Lucky Tickets

题目传送门 1 /* 2 题意:转换就是求n位数字,总和为s/2的方案数 3 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 4 高精度直接拿JayYe的:) 5 异或运算的规则: 6 0⊕0=0,0⊕1=1 7 1⊕0=1,1⊕1=0 8 口诀:相同取0,相异取1 9 */ 10 #include <cstdio> 11 #include <cstring> 12 #include <string>

Ural 1036 Lucky Tickets

Lucky Tickets Time Limit: 2000ms Memory Limit: 16384KB This problem will be judged on Ural. Original ID: 103664-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

URAL 1035 Lucky Tickets

题意:长度为2n的数字,前N位之和和后面的一样,,,加一起是s........问有多少种不同的数字 首先s是奇数肯定就不行了.... 然后n*2*9<s也不行了...... dp[i][j]+=dp[i-1][j-k];就是加的这位不同的情况·~~~ 这题要用高精度,,,, #include<stdio.h> #include<string.h> #include <algorithm> #include <bits/stdc++.h> using n

ural 1217. Unlucky Tickets

1217. Unlucky Tickets Time limit: 1.0 secondMemory 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 ar

递推DP URAL 1031 Railway Tickets

题目传送门 1 /* 2 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 3 注意:s1与s2大小不一定,坑! 4 详细解释:http://blog.csdn.net/kk303/article/details/6847948 5 */ 6 #include <cstdio> 7 #include <iostream> 8 #include <algorithm> 9 #include <cstring> 10 #include <s

Lucky Tickets URAL - 1036 dp+大数

用b[i][j]表示递推到第i位时数字和为j的方案数,那么总方案数就是b[n][s/2]的平方 1 n, s = input().split(' ') 2 3 n = int(n) 4 s = int(s) 5 6 if s % 2 == 1: 7 print(0) 8 else: 9 s = int(s // 2) 10 b = [[]] 11 a = [] 12 for i in range(0, 10): 13 a.append(1) 14 for i in range(10, s + 1

Lucky Numbers (easy) CodeForces - 96B

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it

C - Lucky Numbers (easy)

Problem description Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number