【不可能的任务5/200】uva12063数位dp

辣鸡军训毁我青春!!!

因为在军训,导致很长时间都只能看书yy题目,而不能溜到机房鏼题

于是在猫大的帮助下我发现这道习题是数位dp

然后想起之前讲dp的时候一直在补作业所以没怎么写,然后就试了试

果然dp的代码比数据结构题短到不知道哪里去了,而且1A,爽啊

 1 #include <cstdio>
 2 int t=1,T,n,m;
 3 long long dp[65][100][130];
 4 int main()
 5 {
 6     for(scanf("%d",&T);t<=T;t++)
 7     {
 8         scanf("%d%d",&n,&m);
 9         printf("Case %d: ",t);
10         if((n&1)||(!m))
11         {
12             printf("0\n");
13             continue;
14         }
15         for(int i=1;i<=n;i++)
16             for(int j=0;j<m;j++)
17                 for(int k=0;k<=2*n;k++)
18                     dp[i][j][k]=0;
19         dp[1][1%m][1+n]=1;
20         for(int i=2;i<=n;i++)
21             for(int j=0;j<m;j++)
22                 for(int k=0;k<=2*n;k++)
23                 {
24                     if(k>0)
25                         dp[i][j*2%m][k-1]+=dp[i-1][j][k];
26                     if(k<2*n)
27                         dp[i][(j*2+1)%m][k+1]+=dp[i-1][j][k];
28                 }
29         printf("%lld\n",dp[n][0][n]);
30     }
31     return 0;
32 }

良心样例,本来我没开longlong的,样例都已经炸int了就改掉了

时间: 2024-08-25 13:18:56

【不可能的任务5/200】uva12063数位dp的相关文章

[暑假集训--数位dp]hdu3652 B-number

A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb

【HDU 3652】 B-number (数位DP)

B-number Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task

hihoCoder1033 交错和 数位DP

题目:交错和 链接:http://hihocoder.com/problemset/problem/1033# 题意:对于一个十进制整数x,令a0.a1.a2.....an是x从高位到低位的数位,定义f(x)=a0-a1+a2-a3+...an,给出L.R.K,x在L到R之间,求所有满足:f(x)=k的x的和.(0 ≤ l ≤ r ≤ 10^18, |k| ≤ 100) 思路: L与R太大,连预处理的可能性都没有,很明显的数位DP. 令dp[i][j]为精确的(有前导0)i 位,f(x)值为j

POJ - 3286 - How many 0&#39;s? 【数位DP】

How many 0's? Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description A Benedict monk No.16 writes down the decimal representations of all natural numbers between and including m and n, m ≤ n. How many 0's will he writ

[数位dp] hihoCoder 1033 交错和

题意: 问你[l,r]区间内的所有满足各个位一加一减最后和是k的全有数的和. 思路: 数位dp dp[site][sum][p][k] 代表site位,和是sum,当前是加还是减,最后和是k的数的和以及个数 也就是存成结构体. 然后求的时候 ans.cnt=(ans.cnt+cur.cnt)%mod; ans.sum=(ans.sum+cur.sum+cur.cnt*tep)%mod; tep为i*当前位的位权. 代码: #include"cstdlib" #include"

hdu3652 数位dp(含13且被能被13整除的数)

http://acm.hdu.edu.cn/showproblem.php?pid=3652 B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2815    Accepted Submission(s): 1552 Problem Description A wqb-number, or B-number for sh

hdu 6148 Valley Numer (数位dp)

Problem Description 众所周知,度度熊非常喜欢数字. 它最近发明了一种新的数字:Valley Number,像山谷一样的数字.当一个数字,从左到右依次看过去数字没有出现先递增接着递减的"山峰"现象,就被称作 Valley Number.它可以递增,也可以递减,还可以先递减再递增.在递增或递减的过程中可以出现相等的情况.比如,1,10,12,212,32122都是 Valley Number.121,12331,21212则不是.度度熊想知道不大于N的Valley Nu

数位DP HDU3652

B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5000    Accepted Submission(s): 2866 Problem Description A wqb-number, or B-number for short, is a non-negative integer whose decimal for

hdu5787(数位dp)

基础的数位dp,才发现今天才终于彻底搞懂了数位dp... // // main.cpp // hdu5787.1 // // Created by New_Life on 16/8/10. // Copyright © 2016年 chenhuan001. All rights reserved. // #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #