#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;
int main()
{
int m,n;
cin>>m>>n;
int a[n^m][m+1];
memset(a,1,sizeof(a));
for(int i=0;i<n^m;i++)
{
for(int j=0;j<m;j++)
{
}
}
for(int i=0;i<n^m;i++)
{
for(int j=1;j<m;j++)
{
if(j%2) //奇数项
{
if(a[i][j]<a[i][j-1])
a[i][m]=0;
}
else
{
if(a[i][j]>a[i][j-1])
a[i][m]=0;
}
}
}
for(int i=0;i<n^m;i++)
{
if(a[i][m])
{
for(int j=0;j<m;j++)
{
cout<<a[i][j]<<" ";
}
}
cout<<endl;
}
}
拿C#给你写一个
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Q1064385
{
class Program
{
static IEnumerable<List<int>> foo(List<int> seed, int seedn, int remain, List<int> range)
{
if (remain == 0)
{
yield return seed;
}
else if (seed == null)
{
foreach (var item in foo(Enumerable.Repeat(0, remain).ToList(), 0, remain, range))
yield return item;
}
else
{
Func<int, bool> cond1 = x => x > range.Min();
Func<int, bool> cond2 = x => x > seed[seedn - 1];
Func<int, bool> cond3 = x => x < seed[seedn - 1];
foreach (var i in range.Where(seedn == 0 ? cond1 : (seedn % 2 == 0 ? cond2 : cond3)))
{
var newlist = seed.ToList();
newlist[seedn] = i;
foreach (var item in foo(newlist, seedn + 1, remain - 1, range))
yield return item;
}
}
}
static void Main(string[] args)
{
string s = Console.ReadLine();
int m = int.Parse(s.Split(' ')[0]);
int n = int.Parse(s.Split(' ')[1]);
var result = foo(null, 0, m, Enumerable.Range(1, n).ToList());
foreach (var item in result)
Console.WriteLine(string.Join(" ", item.Select(x => x.ToString())));
Console.WriteLine(result.Count());
}
}
}
3 4
2 1 2
2 1 3
2 1 4
3 1 2
3 1 3
3 1 4
3 2 3
3 2 4
4 1 2
4 1 3
4 1 4
4 2 3
4 2 4
4 3 4
14
Press any key to continue . . .