Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 11, 55, 1010and 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 I, V, X, L.
The only line of the input file contains a single integer nn (1≤n≤1091≤n≤109) — the number of roman digits to use.
Output a single integer — the number of distinct integers which can be represented using nn roman digits exactly.
1
4
2
10
10
244
In the first sample there are exactly 44 integers which can be represented — I, V, X 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);
}