首页 > 其他分享 >UVa 11375 Matches (DP&高精度)

UVa 11375 Matches (DP&高精度)

时间:2023-04-12 11:35:17浏览次数:47  
标签:node const 11375 matches ++ len int UVa DP


11375 - Matches

Time limit: 2.000 seconds

http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2370

We can make digits with matches as shown below:

Given N matches, find the number of different numbers representable using the matches. We shall only make numbers greater than or equal to 0, so no negative signs should be used. For instance, if you have 3 matches, then you can only make the numbers 1 or 7. If you have 4 matches, then you can make the numbers 1, 4, 7 or 11. Note that leading zeros are not allowed (e.g. 001, 042, etc. are illegal). Numbers such as 0, 20, 101 etc. are permitted, though.

Input

Input contains no more than 100 lines. Each line contains one integer N (1 ≤ N ≤ 2000).

Output

For each N, output the number of different (non-negative) numbers representable if you have N matches.

Sample Input


3 4


Sample Output


2 4



简单DP。


完整代码:

/*0.076s*/

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 2001;
const int c[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; ///  c[i]表示数字i需要的火柴数

struct node
{
	int p[500], len;

	node()
	{
		memset(p, 0, sizeof(p));
		len = 0;
	}

	node(int a)
	{
		p[0] = a;
		len = 1;
	}

	node operator + (const node& a) const
	{
		node b;
		b.len = max(len, a.len);
		for (int i = 0; i < b.len; i++)
		{
			b.p[i] += p[i] + a.p[i];
			b.p[i + 1] = b.p[i] / 10;
			b.p[i] %= 10;
		}
		if (b.p[b.len] > 0) b.len++;
		return b;
	}

	node operator += (const node& a)
	{
		*this = *this + a;
		return *this;
	}

	void out()
	{
		if (len == 0) putchar('0');
		else
		{
			for (int i = len - 1; i >= 0; i--)
				printf("%d", p[i]);
		}
		putchar(10);
	}
} d[maxn];

int main()
{
	int i, j, n;
	d[0] = node(1);
	for (i = 0; i < maxn; ++i)
		for (j = 0; j < 10; ++j)
			if (i + c[j] < maxn && (i || j))
				d[i + c[j]] += d[i];
	d[6] += node(1);
	for (i = 2; i < maxn; ++i) d[i] += d[i - 1];
	while (~scanf("%d", &n))
		d[n].out();
	return 0;
}




标签:node,const,11375,matches,++,len,int,UVa,DP
From: https://blog.51cto.com/u_5535544/6185337

相关文章

  • UVa 11507 Bender B. Rodríguez Problem (模拟&异或)
    11507-BenderB.RodríguezProblemTimelimit:4.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2502Benderisarobotbuiltby Mom'sFriendlyRobotCompany atits......
  • UVa 443 / POJ 2247 Humble Numbers (4因子-丑数&STL灵活运用)
    443-HumbleNumbersTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=384http://poj.org/problem?id=2247Anumberwhoseonlyprimefactorsare2,3,5or7isc......
  • UVa 10673 Play with Floor and Ceil (数论)
    10673-PlaywithFloorandCeilTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1614TheoremForanytwointegers x and k thereexiststwomoreintegers p ......
  • UVa 10004 Bicoloring (DFS&二分图)
    10004-BicoloringTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=945In1976the``FourColorMapTheorem"wasprovenwiththeassistanceofacomput......
  • UVa 143 Orchard Trees (数学&计算几何&枚举)
    143-OrchardTreesTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=79AnOrchardisthasplantedanorchardinarectanglewithtreesuniformlyspacedinbothdirections.T......
  • 以阿里巴巴推荐的使用 ThreadPoolExecutor 构造函数自定义参数的方式来创建线程池
    importjava.util.concurrent.ArrayBlockingQueue;importjava.util.concurrent.ThreadPoolExecutor;importjava.util.concurrent.TimeUnit;publicclassThreadPoolExecutorDemo{privatestaticfinalintCORE_POOL_SIZE=5;privatestaticfinalintMAX......
  • Semi-prime H-numbers UVA - 11105
     所有形如4n+1(n为非负整数)的数叫H数。定义1是唯一的单位H数,H素数是指本身不是1,且不能写成两个不是1的H数的乘积。H-半素数是指能写成两个H素数的乘积的H数(这两个数可以相同也可以不同)。 例如,25是H-半素数,但125不是。输入一个H数h(h≤1000001),输出1~h之间有多少个H-半素数。......
  • 【Java 线程池】【四】ThreadPoolExector中的Worker工作者原理
    1 前言上一节我们看了ThreadPoolExecutor线程池的execute内部方法流程,addWorker方法流程,看到Worker是线程池内部的工作者,每个Worker内部持有一个线程,addWorker方法创建了一个Worker工作者,并且放入HashSet的容器中,那么这节我们就来看看Worker是如何工作的。2  内部属性我们......
  • 博弈论dp
    博弈DP解决的是两人轮流操作,且没有平局的两人博弈游戏,和博弈问题的形式相同。博弈论dp正推会有后效性,这是无法解决的所以一般博弈论dp会选着逆推但实际上逆推也不好写,所以这时候一般会以记忆化搜索dp的形式来写博弈论dp ......
  • 康复训练の树形DP
    所有代码的开头头文件,宏定义和命名空间如下#include<bits/stdc++.h>#defineTptemplate<typenameTy>#defineTstemplate<typenameTy,typename...Ar>#definelllonglong#defineCIconstint#defineRIint#defineWwhile#definegcgetchar#definemax(x,y)......