JK01WYX @ 2023-11-12 20:50:56
大神们麻烦跑一下,w(20,20,20)(注释部分)会给出21的结果,如果注释掉自己输入20 20 20,结果就是很大一个数; 蒟蒻看了半个多小时了,这个没法调试啊
#define _CRT_SECURE_NO_WARNINGS 1
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
using namespace std;
#include <unordered_map>
#include <vector>
#include <math.h>
#include <list>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <string>
#include <algorithm>//sort
#include <stdlib.h>
#include <iomanip>
#include <cstring>//memset
#include <limits.h>
/*ios::sync_with_stdio(false);
cin.tie(0);*/
//long long a, b, p;//a^b mod p=s
//long long fp(int c)
//{
// if (c == 1)return a % p;
// long long tmp = fp(c / 2);
// if (c % 2 == 0)
// return tmp * tmp % p;
// else
// return tmp * tmp % p * a % p;
//}
long long a, b, c;
long long arr[25][25][25] = { 0 };
long long w(long long af,long long bf,long long cf)
{
if (af <= 0 || bf <= 0 || cf <= 0)
return 1;
if (af > 20 || bf > 20 || cf > 20)
return w(20,20,20);
if (arr[af][bf][cf])
return arr[af][bf][cf];
if (af < bf && bf < cf)
{
arr[af][bf][cf] =
w(af, bf, cf - 1)
+ w(af, bf - 1, cf - 1)
- w(af, bf - 1, cf);
return arr[af][bf][cf];
}
arr[af][bf][cf] = w(af - 1, bf, cf)
+ w(af - 1, bf - 1, c)
+ w(af - 1, bf, cf - 1)
- w(af - 1, bf - 1, cf - 1);
return arr[af][bf][cf];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
//cout << w(20, 20, 20) << endl;
while (1)
{
cin >> a >> b >> c;
if (a == -1 && b == -1 && c == -1)break;
cout << "w(" << a << ", " << b << ", " << c << ") = " << w(a, b, c) << endl;
}
return 0;
}
by JK01WYX @ 2023-11-13 10:27:22
@JK01WYX 是因为函数有个cf输的是c,名字起的太烂了