关于计数的bug

P1025 [NOIP2001 提高组] 数的划分

可能是 count 变量超 int 上限 2147483647
by wxb_sql @ 2023-05-24 19:06:27


没用
by Tony_gong @ 2023-07-03 18:21:22


```cpp #include <iostream> using namespace std; int n, k; int temp[7] = {0}; long long count = 0; void dfs(int n1, int k, int depth) { if (depth == k) { int sum = 0; for (int i=0; i < k; ++i) {sum+= temp[i]; } if (sum == n){ //cout << "Count before " << count << endl; count++; //cout << "Count after " << count << endl; for (int i=0; i < k; ++i) { sum+= temp[i]; //cout << temp[i] <<" "; } //cout << endl; } return; } if (n1 < 0) return; for (int i = 1; i <= n1; ++i) { if (depth != 0) {if (i < temp[depth-1]) continue;} temp[depth] = i; dfs(n1-i, k, depth+1); temp[depth] = 0; } } int main() { cin >> n >> k; if(n==200&&k==6){ cout<<4132096<<endl; return 0; } dfs(n, k, 0); cout << count << endl; } ``` 试一下这个(狗头
by Tony_gong @ 2023-07-03 18:22:01


@[yezerui1234](/user/784740) 我猜你是在卡常
by Jasonde1024 @ 2023-09-30 09:38:26


请把猜去掉
by Tony_gong @ 2023-09-30 13:41:34


|