feat(DP): new problem formated
This commit is contained in:
68
analise-de-dados/src/ac.cpp
Normal file
68
analise-de-dados/src/ac.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
rollMax[i] = n -> at most n dices of value i consecutive
|
||||
|
||||
let dp[i][{1,2,3,4,5,6}] be the number of valid sequences of length i where the last dice was j
|
||||
|
||||
we can extend this in the following way
|
||||
|
||||
for all k such that k != j
|
||||
dp[i + 1][k] += dp[i][j]
|
||||
dp[i + 2][k] += dp[i][j]
|
||||
...
|
||||
dp[i + rollMax[k]][k] += dp[i][j]
|
||||
|
||||
dp[0][j] = 1 for all j E {1,2,3,4,5,6}
|
||||
|
||||
answer = sum (dp[N][j]) for all j E {1,2,3,4,5,6}
|
||||
*/
|
||||
const int MOD = 1e9 + 7;
|
||||
int dieSimulator(int n, vector<int> &rollMax)
|
||||
{
|
||||
vector<vector<long long>> dp(n + 1, vector<long long>(6, 0));
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
for (int rolls = 0; rolls <= rollMax[i] && rolls <= n; ++rolls)
|
||||
{
|
||||
dp[rolls][i] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
if (dp[i][j] == 0)
|
||||
continue;
|
||||
for (int k = 0; k < 6; k++)
|
||||
{
|
||||
if (k == j)
|
||||
continue;
|
||||
for (int m = 1; m <= rollMax[k] && i + m <= n; m++)
|
||||
{
|
||||
dp[i + m][k] += dp[i][j];
|
||||
dp[i + m][k] %= MOD;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long long ans = 0;
|
||||
for (int i = 0; i < 6; i++)
|
||||
ans += dp[n][i];
|
||||
return ans % MOD;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<int> nums(6);
|
||||
for (int i = 0; i < 6; i++)
|
||||
cin >> nums[i];
|
||||
cout << dieSimulator(n, nums) << endl;
|
||||
return 0;
|
||||
}
|
||||
19
analise-de-dados/src/checker.cpp
Normal file
19
analise-de-dados/src/checker.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
setName("compare two signed int%d's", 8 * int(sizeof(int)));
|
||||
registerTestlibCmd(argc, argv);
|
||||
|
||||
int ja = ans.readInt();
|
||||
int pa = ouf.readInt();
|
||||
|
||||
if (ja != pa)
|
||||
quitf(_wa, "expected %d, found %d", ja, pa);
|
||||
|
||||
quitf(_ok, "answer is %d", ja);
|
||||
}
|
||||
98
analise-de-dados/src/generator.cpp
Normal file
98
analise-de-dados/src/generator.cpp
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MIN_N = 1;
|
||||
const int MAX_N = 5000;
|
||||
const int MIN_NI = 1;
|
||||
const int MAX_NI = 15;
|
||||
|
||||
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 n, const vector<int>& nums) {
|
||||
ostringstream oss;
|
||||
oss << n << endl;
|
||||
for (int i = 0; i < nums.size(); i++) {
|
||||
if (i != 0) oss << " ";
|
||||
oss << nums[i];
|
||||
}
|
||||
oss << endl;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
vector<string> generate_sample_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(2, {1, 1, 2, 2, 2, 3}));
|
||||
tests.push_back(output_tc(2, {1, 1, 1, 1, 1, 1}));
|
||||
tests.push_back(output_tc(3, {1, 1, 1, 2, 2, 3}));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<string> generate_manual_tests() {
|
||||
vector<string> tests;
|
||||
tests.push_back(output_tc(2, {2, 2, 2, 2, 2, 2}));
|
||||
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 = 5;
|
||||
}
|
||||
else if(i<rnd_test_n / 2){
|
||||
max_n = 20;
|
||||
}
|
||||
|
||||
int x = rnd.next(min_n, max_n);
|
||||
vector<int> nums(6);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
nums[i] = rnd.next(MIN_NI, MAX_NI);
|
||||
}
|
||||
|
||||
return(output_tc(x, nums));
|
||||
}
|
||||
|
||||
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(){
|
||||
vector<int> nums(6);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
nums[i] = MAX_NI;
|
||||
}
|
||||
|
||||
return(output_tc(MAX_N, nums));
|
||||
}
|
||||
|
||||
vector<string> generate_extreme_tests(){
|
||||
vector<string> tests;
|
||||
tests.push_back(extreme_test_1());
|
||||
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
analise-de-dados/src/script.sh
Normal file
1
analise-de-dados/src/script.sh
Normal file
@@ -0,0 +1 @@
|
||||
generator
|
||||
5963
analise-de-dados/src/testlib.h
Normal file
5963
analise-de-dados/src/testlib.h
Normal file
File diff suppressed because it is too large
Load Diff
18
analise-de-dados/src/validator.cpp
Normal file
18
analise-de-dados/src/validator.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "testlib.h"
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
inf.readInt(1, 5000, "n");
|
||||
inf.readEoln();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (i != 0) inf.readSpace();
|
||||
inf.readInt(1, 15, "di");
|
||||
}
|
||||
inf.readEoln();
|
||||
inf.readEof();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user