Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following.
A sequence of l integers b 1, b 2, ..., bl (1 ≤ b 1 ≤ b 2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally
for all i (1 ≤ i ≤ l - 1).
Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007 (109 + 7).
总结一下题目让干啥 具体来说,题目让计算长度为 k 的序列个数,其中每个元素都是 1 到 n 之间的整数,且序列中每个元素都是前一个元素的倍数,我们举个例子,看题上给的样例序列长度为2时这五个[1, 1], [2, 2], [3, 3], [1, 2], [1, 3] ,我们只要看末尾值,给末尾值找个倍数,在这个序列后面续上,这就能保证每个数都能整除后面的数,然后我们就可以继承上次长度的序列的个数了
从上面叙述来说,我们可以得到我们的dp数组和末尾的数以及当前序列的长度有关所以dp[i][j]表示以 i 结尾的长度为 j 的序列数量,看代码吧
cpp复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int dp[2020][2020];
signed main() {
int n,k;
cin>>n>>k;
//每个数单独作为一个序列
for(int i=1;i<=n;i++) dp[i][1]=1;
for(int j=2;j<=k;j++){
for(int i=1;i<=n;i++){
for(int db=1;db*i<=n;db++){
(dp[i*db][j]+=dp[i][j-1])%=mod;
}
}
}
int ans=0;
for(int i=1;i<=n;i++){
(ans+=dp[i][k])%=mod;
}
cout<<ans<<endl;
return 0;
}
A. Elimination
time limit per test
1 second
memory limit per test
256 megabytes
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.
The elimination rounds are divided into main and additional. Each of the main elimination rounds consists of c problems, the winners of the round are the first n people in the rating list. Each of the additional elimination rounds consists of d problems. The winner of the additional round is one person. Besides, k winners of the past finals are invited to the finals without elimination.
As a result of all elimination rounds at least n ·m people should go to the finals. You need to organize elimination rounds in such a way, that at least n ·m people go to the finals, and the total amount of used problems in all rounds is as small as possible.
DeepL 翻译
2214 年 "俄罗斯代码杯 "竞赛的决赛选手将是在淘汰赛中获胜的参赛者。
淘汰赛分为正赛和附加赛。主淘汰赛每轮由 c 个问题组成,获胜者为评分表中排名前 n 位的选手。附加淘汰赛每轮由 d 道题组成。附加赛的获胜者为一人。此外,往届决赛的 k 名优胜者将被邀请参加决赛,无需参加淘汰赛。
所有淘汰赛的结果是至少有 n ·m 人进入决赛。您需要以这样一种方式组织淘汰赛,即至少有 n ·m 人进入决赛,并且所有淘汰赛中使用的问题总数越少越好。
Input
The first line contains two integers c and d (1 ≤ c , d ≤ 100) --- the number of problems in the main and additional rounds, correspondingly. The second line contains two integers n and m (1 ≤ n , m ≤ 100). Finally, the third line contains an integer k (1 ≤ k ≤ 100) --- the number of the pre-chosen winners.
DeepL 翻译
输入
第一行包含两个整数 c 和 d ( 1 ≤ c , d ≤ 100 ) --相应的主轮和附加轮的问题数。第二行包含两个整数 n 和 m ( 1 ≤ n , m ≤ 100 )。( 1 ≤ n , m ≤ 100 ).最后,第三行包含一个整数 k ( 1 ≤ k ≤ 100 ) --预选获胜者的人数。
Output
In the first line, print a single integer --- the minimum number of problems the jury needs to prepare.
沿路有 n 棵树,坐标为 x 1, x 2, ..., xn 。每棵树的高度为 hi 。伐木工人可以砍倒一棵树,并将其砍向左边或右边。之后,它就会占据 [xi - hi , xi ] 或 [xi ;xi + hi ] 中的一段。未被砍伐的树木占据坐标为 xi 的一个点。如果倒下的树所占据的线段不包含任何被占据的点,伐木工人就可以砍树。伐木工人希望尽可能多地砍伐树木,因此苏西想知道最多可以砍伐多少棵树?
输入
第一行包含整数 n ( 1 ≤ n ≤ 105 )--树木数量。( 1 ≤ n ≤ 105 ) - 树的数量。
接下来的 n 行包含一对整数 xi , hi ( 1 ≤ xi , hi ≤ 109 ) - 第 і 棵树的坐标和高度。
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+20;
int dp[N][3];
int a[N],b[N];
int n;
signed main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
dp[1][1]=a[1];
dp[1][2]=b[1];
for(int i=2;i<=n;i++){
dp[i][0]=max(max(dp[i-1][0],dp[i-1][1]),dp[i-1][2]);
dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i];
dp[i][2]=max(dp[i-1][0],dp[i-1][1])+b[i];
}
cout<<max(max(dp[n][0],dp[n][1]),dp[n][2]);
return 0;
}