HDOJ1466(计算直线的交点数)dp
#include <iostream>
#include <set>
using namespace std;
const int N = 22;
int main()
{
set<int> S[N];//
set<int>::iterator p;
int fa[N];//相交方案数
int i, k;
//=====================================
S[0].clear();
S[0].insert(0);
fa[0] = 1;
//============================
for(i = 1; i <= 20; i++)
{
S[i].clear();
for(k = 0; k < i; k++)
{
p = S[k].begin();
while(p != S[k].end())
{
S[i].insert((i - k) * k + *p);
p++;
}
}
}
while(cin>>k)
{
p = S[k].begin();
cout<<*p;
p++;
while(p != S[k].end())
{
cout<<" "<<*p;
p++;
}
cout<<endl;
}
return 0;
}
#include <set>
using namespace std;
const int N = 22;
int main()
{
set<int> S[N];//
set<int>::iterator p;
int fa[N];//相交方案数
int i, k;
//=====================================
S[0].clear();
S[0].insert(0);
fa[0] = 1;
//============================
for(i = 1; i <= 20; i++)
{
S[i].clear();
for(k = 0; k < i; k++)
{
p = S[k].begin();
while(p != S[k].end())
{
S[i].insert((i - k) * k + *p);
p++;
}
}
}
while(cin>>k)
{
p = S[k].begin();
cout<<*p;
p++;
while(p != S[k].end())
{
cout<<" "<<*p;
p++;
}
cout<<endl;
}
return 0;
}