Codeforces Round #493 (Div. 2)D. Roman Digits 第一道打表找规律题目

本文探讨了一种基于I、V、X、L四个罗马数字的计数系统,介绍了一个算法来确定使用特定数量的这些罗马数字能表示的不同整数的数量。通过深度优先搜索和集合存储策略,文章提供了一个解决方案,并通过实例说明了该系统的特性和计算过程。
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 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.

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 — 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).

 

打表找规律

下面为打表程序

#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define  pi acos(-1.0)
#define  eps 1e-6
#define  fi first
#define  se second
#define  lson l,m,rt<<1
#define  rson m+1,r,rt<<1|1
#define  bug         printf("******\n")
#define  mem(a,b)    memset(a,b,sizeof(a))
#define  fuck(x)     cout<<"["<<x<<"]"<<endl
#define  f(a)        a*a
#define  sf(n)       scanf("%d", &n)
#define  sff(a,b)    scanf("%d %d", &a, &b)
#define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define  pf          printf
#define  FRE(i,a,b)  for(i = a; i <= b; i++)
#define  FREE(i,a,b) for(i = a; i >= b; i--)
#define  FRL(i,a,b)  for(i = a; i < b; i++)
#define  FRLL(i,a,b) for(i = a; i > b; i--)
#define  FIN         freopen("DATA.txt","r",stdin)
#define  gcd(a,b)    __gcd(a,b)
#define  lowbit(x)   x&-x
#pragma  comment (linker,"/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 10;
set<int>st;
int n,sum=0;
int val[5]={1,5,10,50};
void dfs(int x) {
    if (x==n+1){
        st.insert(sum);
        return ;
    }
    for (int i=0 ;i<4 ;i++){
        sum+=val[i];
        dfs(x+1);
        sum-=val[i];
    }
}
int main() {
    for (int i=1 ;i<=60 ;i++) {
        n=i;
        sum=0;
        st.clear();
        dfs(1);
        printf("%d ",st.size());
    }
    return 0;
}

 

 

 

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <queue>
 4 #include <cmath>
 5 #include <algorithm>
 6 #include <set>
 7 #include <iostream>
 8 #include <map>
 9 #include <stack>
10 #include <string>
11 #include <vector>
12 #define  pi acos(-1.0)
13 #define  eps 1e-6
14 #define  fi first
15 #define  se second
16 #define  lson l,m,rt<<1
17 #define  rson m+1,r,rt<<1|1
18 #define  bug         printf("******\n")
19 #define  mem(a,b)    memset(a,b,sizeof(a))
20 #define  fuck(x)     cout<<"["<<x<<"]"<<endl
21 #define  f(a)        a*a
22 #define  sf(n)       scanf("%d", &n)
23 #define  sff(a,b)    scanf("%d %d", &a, &b)
24 #define  sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
25 #define  sffff(a,b,c,d) scanf("%d %d %d %d", &a, &b, &c, &d)
26 #define  pf          printf
27 #define  FRE(i,a,b)  for(i = a; i <= b; i++)
28 #define  FREE(i,a,b) for(i = a; i >= b; i--)
29 #define  FRL(i,a,b)  for(i = a; i < b; i++)
30 #define  FRLL(i,a,b) for(i = a; i > b; i--)
31 #define  FIN         freopen("DATA.txt","r",stdin)
32 #define  gcd(a,b)    __gcd(a,b)
33 #define  lowbit(x)   x&-x
34 #pragma  comment (linker,"/STACK:102400000,102400000")
35 using namespace std;
36 typedef long long LL;
37 typedef unsigned long long ULL;
38 const int maxn = 1e5 + 10;
39 int ans[50]={0,4,10,20,35,56,83,116,155,198,244,292};
40 int main() {
41     LL n;
42     scanf("%lld",&n);
43     if (n<=11) printf("%d\n",ans[n]);
44     else  printf("%lld\n",292+(n-11)*49);
45     return  0;
46 }

 

转载于:https://www.cnblogs.com/qldabiaoge/p/9445805.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值