Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
a772185e
Commit
a772185e
authored
6 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Fix matrix and linear recurrence
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
0218c476
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
algorithms/math/linear_recurrence.cpp
+5
-3
5 additions, 3 deletions
algorithms/math/linear_recurrence.cpp
algorithms/math/matrix.cpp
+6
-9
6 additions, 9 deletions
algorithms/math/matrix.cpp
with
11 additions
and
12 deletions
algorithms/math/linear_recurrence.cpp
+
5
−
3
View file @
a772185e
...
@@ -25,13 +25,15 @@
...
@@ -25,13 +25,15 @@
* [x1 x2]^n
* [x1 x2]^n
* [ 1 0]
* [ 1 0]
*/
*/
matrix
solve
(
ll
x
,
ll
y
,
ll
n
)
{
template
<
typename
T
>
matrix
in
(
2
);
matrix
<
T
>
solve
(
ll
x
,
ll
y
,
ll
n
)
{
matrix
<
T
>
in
(
2
);
// Example
in
[
0
][
0
]
=
x
%
MOD
;
in
[
0
][
0
]
=
x
%
MOD
;
in
[
0
][
1
]
=
y
%
MOD
;
in
[
0
][
1
]
=
y
%
MOD
;
in
[
1
][
0
]
=
1
;
in
[
1
][
0
]
=
1
;
in
[
1
][
1
]
=
0
;
in
[
1
][
1
]
=
0
;
return
fast_pow
(
in
,
n
);
return
fast_pow
<
T
>
(
in
,
n
);
}
}
This diff is collapsed.
Click to expand it.
algorithms/math/matrix.cpp
+
6
−
9
View file @
a772185e
...
@@ -2,20 +2,21 @@
...
@@ -2,20 +2,21 @@
* Matrix
* Matrix
*/
*/
template
<
typename
T
>
struct
matrix
{
struct
matrix
{
int
r
,
c
;
int
r
,
c
;
vector
<
vector
<
ll
>>
m
;
vector
<
vector
<
T
>>
m
;
matrix
(
int
k
)
:
r
(
k
),
c
(
k
)
{
matrix
(
int
k
)
:
r
(
k
),
c
(
k
)
{
m
=
vector
<
vector
<
ll
>>
(
k
,
vector
<
ll
>
(
k
,
0
));
m
=
vector
<
vector
<
T
>>
(
k
,
vector
<
T
>
(
k
,
0
));
}
}
matrix
(
int
r
,
int
c
)
:
r
(
r
),
c
(
c
)
{
matrix
(
int
r
,
int
c
)
:
r
(
r
),
c
(
c
)
{
m
=
vector
<
vector
<
ll
>>
(
r
,
vector
<
ll
>
(
c
,
0
));
m
=
vector
<
vector
<
T
>>
(
r
,
vector
<
T
>
(
c
,
0
));
}
}
matrix
operator
*
(
matrix
a
)
{
matrix
operator
*
(
matrix
a
)
{
assert
(
r
==
a
.
c
&&
c
=
a
.
r
);
assert
(
r
==
a
.
c
&&
c
=
=
a
.
r
);
matrix
res
(
r
,
c
);
matrix
res
(
r
,
c
);
for
(
int
i
=
0
;
i
<
r
;
i
++
)
for
(
int
i
=
0
;
i
<
r
;
i
++
)
...
@@ -47,11 +48,7 @@ struct matrix {
...
@@ -47,11 +48,7 @@ struct matrix {
m
[
i
][
i
]
=
1
;
m
[
i
][
i
]
=
1
;
}
}
ll
*
operator
[](
int
i
)
{
vector
<
T
>
&
operator
[](
int
i
)
{
return
m
[
i
];
return
m
[
i
];
}
}
void
clear
()
{
mset
(
m
,
0
);
}
};
};
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment