feat(DP): new dp problems formated
This commit is contained in:
25
flowers/src/ac.cpp
Normal file
25
flowers/src/ac.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
typedef long long ll;
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
int N, M; cin >> N >> M;
|
||||
|
||||
vector<vector<ll>> dp(N + 1, vector<ll>(2, 0));
|
||||
// DP[i][j] := Number of configurations where:
|
||||
// i := length of the arrangement of flowers (first i flowers placed)
|
||||
// j := 0 or 1 (represents the type of the last flower placed)
|
||||
dp[0][0] = dp[0][1] = 1;
|
||||
for (int i = 0; i <= N; i++) {
|
||||
for (int j = 0; j <= 1; j++) {
|
||||
int opposite = (int)(!j);
|
||||
for (int k = 1; k <= M && i + k <= N; k++) {
|
||||
dp[i + k][opposite] += dp[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << dp[N][0] + dp[N][1] << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
18
flowers/src/checker.cpp
Normal file
18
flowers/src/checker.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
setName("compare two numbers");
|
||||
registerTestlibCmd(argc, argv);
|
||||
long long ja = ans.readLong();
|
||||
long long pa = ouf.readLong();
|
||||
|
||||
if (ja != pa)
|
||||
quitf(_wa, "expected %lld, found %lld", ja, pa);
|
||||
|
||||
quitf(_ok, "answer is %lld", ja);
|
||||
|
||||
return 0;
|
||||
}
|
||||
97
flowers/src/generator.cpp
Normal file
97
flowers/src/generator.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_N = 1;
|
||||
const int MAX_N = 1e4;
|
||||
const int MIN_M = 1;
|
||||
const int MAX_M = 1e3;
|
||||
|
||||
const int rnd_test_n = 100;
|
||||
|
||||
template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
|
||||
dest.insert(dest.end(), orig.begin(), orig.end());
|
||||
}
|
||||
|
||||
string output_tc(int x, int y) {
|
||||
ostringstream oss;
|
||||
oss << x << " " << y << endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(1, 1));
|
||||
tests.push_back(output_tc(2, 2));
|
||||
tests.push_back(output_tc(2, 3));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<string> generate_manual_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(100, 20));
|
||||
tests.push_back(output_tc(4, 100));
|
||||
return tests;
|
||||
}
|
||||
|
||||
string rnd_test(int i){
|
||||
int min_n = MIN_N;
|
||||
int max_n = MAX_N;
|
||||
|
||||
if(i<rnd_test_n / 3){
|
||||
max_n = MAX_N/5;
|
||||
}
|
||||
else if(i<rnd_test_n / 2){
|
||||
max_n = MAX_N/2;
|
||||
}
|
||||
|
||||
int x = rnd.next(min_n, max_n);
|
||||
int y = rnd.next(MIN_M, MAX_M);
|
||||
return(output_tc(x, y));
|
||||
}
|
||||
|
||||
vector<string> generate_random_tests() {
|
||||
vector<string> tests;
|
||||
for (int i = 0; i < rnd_test_n; i++){
|
||||
tests.push_back(rnd_test(i));
|
||||
}
|
||||
return tests;
|
||||
}
|
||||
|
||||
string extreme_test_1(){
|
||||
return(output_tc(MAX_N, MIN_M));
|
||||
}
|
||||
string extreme_test_2(){
|
||||
return(output_tc(MAX_N, MAX_M));
|
||||
}
|
||||
string extreme_test_3(){
|
||||
return(output_tc(MIN_N, MAX_M));
|
||||
}
|
||||
string extreme_test_4(){
|
||||
return(output_tc(MIN_N, MIN_M));
|
||||
}
|
||||
|
||||
vector<string> generate_extreme_tests(){
|
||||
vector<string> tests;
|
||||
tests.push_back(extreme_test_1());
|
||||
tests.push_back(extreme_test_2());
|
||||
tests.push_back(extreme_test_3());
|
||||
tests.push_back(extreme_test_4());
|
||||
return tests;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
registerGen(argc, argv, 1);
|
||||
vector<string> tests;
|
||||
size_t test = 0;
|
||||
append(tests, generate_sample_tests());
|
||||
append(tests, generate_manual_tests());
|
||||
append(tests, generate_random_tests());
|
||||
append(tests, generate_extreme_tests());
|
||||
for (const auto &t : tests) {
|
||||
startTest(++test);
|
||||
cout << t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
1
flowers/src/script.sh
Normal file
1
flowers/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
flowers/src/testlib.h
Normal file
5963
flowers/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
15
flowers/src/validator.cpp
Normal file
15
flowers/src/validator.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
inf.readInt(1, 1e4, "n");
|
||||
inf.readSpace();
|
||||
inf.readInt(1, 1000, "m");
|
||||
inf.readEoln();
|
||||
inf.readEof();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user