From 5565beca67266d65b28d0c0ad5d1a06178ede73f Mon Sep 17 00:00:00 2001 From: omagdy7 Date: Mon, 27 May 2024 16:30:12 +0300 Subject: Solved two dp problems on cses --- cses/IntroductoryProblems/BitStrings/main.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'cses/IntroductoryProblems/BitStrings/main.cpp') diff --git a/cses/IntroductoryProblems/BitStrings/main.cpp b/cses/IntroductoryProblems/BitStrings/main.cpp index cb4a7fb..480a9ae 100755 --- a/cses/IntroductoryProblems/BitStrings/main.cpp +++ b/cses/IntroductoryProblems/BitStrings/main.cpp @@ -1,16 +1,17 @@ -#include +#include using namespace std; -int main () { +int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; int m = 1e9 + 7; cin >> n; - long long ans = 0; - while(n--) { - ans += ((2 % m) * (2 % m)) % m; + n--; + long long ans = 2; + while (n--) { + ans = ((ans % m) * 2) % m; } cout << ans << '\n'; } -- cgit v1.2.3