打卡Day4 洛谷P2089

原题链接

傻瓜式编程暴力解决,就是要注意数组得开的足够大否则会报RE

#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;
int n, sum = 0;
int p[10000][15], t[15];
int  main()
{
	cin >> n;
	if (n < 10 || n>30) {
		cout << 0;
	}
	else {
		for (t[1] = 1; t[1] <= 3; t[1]++) {
			for (t[2] = 1; t[2] <= 3; t[2]++) {
				for (t[3] = 1; t[3] <= 3; t[3]++) {
					for (t[4] = 1; t[4] <= 3; t[4]++) {
						for (t[5] = 1; t[5] <= 3; t[5]++) {
							for (t[6] = 1; t[6] <= 3; t[6]++) {
								for (t[7] = 1; t[7] <= 3; t[7]++) {
									for (t[8] = 1; t[8] <= 3; t[8]++) {
										for (t[9] = 1; t[9] <= 3; t[9]++) {
											for (t[10] = 1; t[10] <= 3; t[10]++) {
												if (accumulate(t + 1, t + 11, 0) == n) {
													for (int i = 1; i <= 10; i++) {
														p[sum][i] = t[i];
 
													}
													sum++;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		cout << sum << endl;
		for (int i = 0; i < sum; i++) {
			for (int j = 1; j <= 10; j++) {
				cout << p[i][j];
				if (j != 10)
					cout << " ";
			}
			cout << endl;
		}
	}
 
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值