Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. int func(int n, int a, int b, int c, int k) {
  5. if(n==1) {
  6. if(k==0 && b+c==0) return 0;
  7. if(k==0 && b+c>0) return 1;
  8. if(k==1 && a+c==0) return 0;
  9. if(k==1 && a+c>0) return 1;
  10. if(k==2 && b+a==0) return 0;
  11. if(k==2 && b+a>0) return 1;
  12. }
  13. else {
  14. if(k==0 && b>0 && c>0) {
  15. return func(n-1, a, b-1, c, 1)+func(n-1, a, b, c-1, 2);
  16. }
  17. if(k==0 && b>0 && c==0) {
  18. return func(n-1, a, b-1, c, 1);
  19. }
  20. if(k==0 && b==0 && c>0) {
  21. return func(n-1, a, b, c-1, 2);
  22. }
  23. if(k==0 && b==0 && c==0) {
  24. return 0;
  25. }
  26. if(k==1 && a>0 && c>0) {
  27. return func(n-1, a-1, b, c, 0)+func(n-1, a, b, c-1, 2);
  28. }
  29. if(k==1 && a>0 && c==0) {
  30. return func(n-1, a-1, b, c, 0);
  31. }
  32. if(k==1 && a==0 && c>0) {
  33. return func(n-1, a, b, c-1, 2);
  34. }
  35. if(k==1 && a==0 && c==0) {
  36. return 0;
  37. }
  38. if(k==2 && b>0 && a>0) {
  39. return func(n-1, a, b-1, c, 1)+func(n-1, a-1, b, c, 0);
  40. }
  41. if(k==2 && b>0 && a==0) {
  42. return func(n-1, a, b-1, c, 1);
  43. }
  44. if(k==2 && b==0 && a>0) {
  45. return func(n-1, a-1, b, c, 0);
  46. }
  47. if(k==2 && b==0 && a==0) {
  48. return 0;
  49. }
  50. }
  51. }
  52. signed main () {
  53. int a, b, c;
  54. cin >> a >> b >> c;
  55. int n=a+b+c, ans=0;
  56. if(n==1) {
  57. cout << 1;
  58. return 0;
  59. }
  60. if(a>0) {
  61. ans+=func(n-1, a-1, b, c, 0);
  62. }
  63. if(b>0) {
  64. ans+=func(n-1, a, b-1, c, 1);
  65. }
  66. if(c>0) {
  67. ans+=func(n-1, a, b, c-1, 2);
  68. }
  69. cout << ans;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement