Codeforces Round #493 (Div. 2) D. Roman Digits

D. Roman Digits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Let's introduce a number system which is based on a roman digits. There are digits IVXL which correspond to the numbers 11551010and 5050 respectively. The use of other roman digits is not allowed.

Numbers in this system are written as a sequence of one or more digits. We define the value of the sequence simply as the sum of digits in it.

For example, the number XXXV evaluates to 3535 and the number IXI — to 1212.

Pay attention to the difference to the traditional roman system — in our system any sequence of digits is valid, moreover the order of digits doesn't matter, for example IX means 1111, not 99.

One can notice that this system is ambiguous, and some numbers can be written in many different ways. Your goal is to determine how many distinct integers can be represented by exactly nn roman digits IVXL.

Input

The only line of the input file contains a single integer nn (1n1091≤n≤109) — the number of roman digits to use.

Output

Output a single integer — the number of distinct integers which can be represented using nn roman digits exactly.

Examples
input
Copy
1
output
Copy
4
input
Copy
2
output
Copy
10
input
Copy
10
output
Copy
244
Note

In the first sample there are exactly 44 integers which can be represented — IVX and L.

In the second sample it is possible to represent integers 22 (II), 66 (VI), 1010 (VV), 1111 (XI), 1515 (XV), 2020 (XX), 5151 (IL), 5555 (VL), 6060 (XL) and 100100

 (LL).



打表找规律

打了几项后规律就已经能看出来了

4,10,20,35,56,83,116,155,198,244,292,341,390,439,……

前边打表输出,后边直接加49,理论上解释是之后已经足够稠密到可以每次多拼出49个数字


打表代码如下

#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <assert.h>
#include <fstream>
using namespace std;
int ans=0,sum=0,n;
set<int> s;
int m[5]={0,1,5,10,50};
void dfs(int t){
	if(t==n+1){
		if(s.find(sum)!=s.end())
			return;
		ans++;
		s.insert(sum);
		return;
	}
	for(int i=1;i<=4;i++){
		sum+=m[i];
		dfs(t+1);
		sum-=m[i];
	}
}
int main(){
 	for(int i=1;i<=60;i++){
 		n=i;
 		dfs(1);
 		cout<<ans<<",";
 		ans=0;
 		sum=0;
 		s.clear();
 	}
}

AC代码如下

#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <assert.h>
#include <fstream>
using namespace std;
int main(){
	long long n;
	cin>>n;
	int m[30]={0,4,10,20,35,56,83,116,155,198,244,292,341,390,439};
	cout<<(n<=11?m[n]:(long long)(n-11)*49+292);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值