码迷,mamicode.com
首页 > 其他好文 > 详细

URAL 1044 Lucky Tickets. Easy!

时间:2014-08-26 02:53:05      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   java   for   ar   div   log   sp   

算是个动态规划,统计和

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 }

 

URAL 1044 Lucky Tickets. Easy!

标签:style   blog   color   java   for   ar   div   log   sp   

原文地址:http://www.cnblogs.com/gwhahaha/p/3936303.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!