Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- int func(int n, int a, int b, int c, int k) {
- if(n==1) {
- if(k==0 && b+c==0) return 0;
- if(k==0 && b+c>0) return 1;
- if(k==1 && a+c==0) return 0;
- if(k==1 && a+c>0) return 1;
- if(k==2 && b+a==0) return 0;
- if(k==2 && b+a>0) return 1;
- }
- else {
- if(k==0 && b>0 && c>0) {
- return func(n-1, a, b-1, c, 1)+func(n-1, a, b, c-1, 2);
- }
- if(k==0 && b>0 && c==0) {
- return func(n-1, a, b-1, c, 1);
- }
- if(k==0 && b==0 && c>0) {
- return func(n-1, a, b, c-1, 2);
- }
- if(k==0 && b==0 && c==0) {
- return 0;
- }
- if(k==1 && a>0 && c>0) {
- return func(n-1, a-1, b, c, 0)+func(n-1, a, b, c-1, 2);
- }
- if(k==1 && a>0 && c==0) {
- return func(n-1, a-1, b, c, 0);
- }
- if(k==1 && a==0 && c>0) {
- return func(n-1, a, b, c-1, 2);
- }
- if(k==1 && a==0 && c==0) {
- return 0;
- }
- if(k==2 && b>0 && a>0) {
- return func(n-1, a, b-1, c, 1)+func(n-1, a-1, b, c, 0);
- }
- if(k==2 && b>0 && a==0) {
- return func(n-1, a, b-1, c, 1);
- }
- if(k==2 && b==0 && a>0) {
- return func(n-1, a-1, b, c, 0);
- }
- if(k==2 && b==0 && a==0) {
- return 0;
- }
- }
- }
- signed main () {
- int a, b, c;
- cin >> a >> b >> c;
- int n=a+b+c, ans=0;
- if(n==1) {
- cout << 1;
- return 0;
- }
- if(a>0) {
- ans+=func(n-1, a-1, b, c, 0);
- }
- if(b>0) {
- ans+=func(n-1, a, b-1, c, 1);
- }
- if(c>0) {
- ans+=func(n-1, a, b, c-1, 2);
- }
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement